MessageQueue.EnableConnectionCache 屬性


取得或設定值,指出應用程式是否會維持連接的快取。Gets or sets a value that indicates whether a cache of connections will be maintained by the application.

 static property bool EnableConnectionCache { bool get(); void set(bool value); };
public static bool EnableConnectionCache { get; set; }
member this.EnableConnectionCache : bool with get, set
Public Shared Property EnableConnectionCache As Boolean



true 表示建立並使用連接快取,否則為 falsetrue to create and use a connection cache; otherwise, false.



下列程式碼範例會取得並設定訊息佇列之屬性的值 EnableConnectionCacheThe following code example gets and sets the value of a message queue's EnableConnectionCache property.

// Set the MessageQueue.EnableConnectionCache property value.
MessageQueue.EnableConnectionCache = false;

// Display the new value of the MessageQueue.EnableConnectionCache
// property.
Console.WriteLine("MessageQueue.EnableConnectionCache: {0}",


連接快取是結構的參考清單,其中包含佇列的讀取或寫入控制碼。A connection cache is a list of references to structures that contain read or write handles to queues. EnableConnectionCache 為時 trueMessageQueue 每次您呼叫、或時,都會從快取中處理, Send(Object) Peek Receive 而不是開啟新的控制碼。When EnableConnectionCache is true, the MessageQueue borrows handles from the cache each time you call Send(Object), Peek, or Receive, rather than open new handles. 這可以改善效能。This can improve performance. 使用連線快取也會將 MessageQueue 網路拓撲中的變更隔離。Using a connection cache also insulates the MessageQueue from changes in the network topology.

如果您在連線快取已滿時建立佇列的新連接,則會 MessageQueue 以新的連接覆寫最近存取的最少結構。If you create a new connection to a queue when the connection cache is full, the MessageQueue overwrites the least recently accessed structure with the new connection. 您可以藉由呼叫來完全清除快取 ClearConnectionCache ,例如,如果您正在使用的佇列格式名稱已變更,使得先前的讀取和寫入控制碼不再有效。You can clear the cache entirely by calling ClearConnectionCache, for example, if the format names of the queues you are working with have changed so that the previous read and write handles are no longer valid.

下表顯示此屬性是否適用于各種工作組模式。The following table shows whether this property is available in various Workgroup modes.

工作組模式Workgroup mode 可用Available
本機電腦Local computer Yes
本機電腦和直接格式名稱Local computer and direct format name Yes
遠端電腦Remote computer Yes
遠端電腦和直接格式名稱Remote computer and direct format name Yes