SortedList<TKey,TValue>.ICollection.SyncRoot SortedList<TKey,TValue>.ICollection.SyncRoot SortedList<TKey,TValue>.ICollection.SyncRoot Property


取得可用以同步存取 ICollection 的物件。Gets an object that can be used to synchronize access to the ICollection.

property System::Object ^ System::Collections::ICollection::SyncRoot { System::Object ^ get(); };
object System.Collections.ICollection.SyncRoot { get; }
 ReadOnly Property SyncRoot As Object Implements ICollection.SyncRoot


可用以同步存取 ICollection 的物件。An object that can be used to synchronize access to the ICollection. SortedList<TKey,TValue> 的預設實作中,這個屬性永遠會傳回目前的執行個體。In the default implementation of SortedList<TKey,TValue>, this property always returns the current instance.



System.Collections.Generic集合的預設實值不會同步處理。Default implementations of collections in System.Collections.Generic are not synchronized.

透過集合進行列舉在本質上並非安全執行緒程序。Enumerating through a collection is intrinsically not a thread-safe procedure. 若要確保列舉期間的執行緒安全性,您可以在整個列舉期間鎖定集合。To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. 若要讓多重執行緒能夠存取集合以便進行讀取和寫入,您必須實作自己的同步處理。To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

屬性會傳回可用來同步存取的ICollection物件。 SyncRootThe SyncRoot property returns an object that can be used to synchronize access to the ICollection. 只有在所有線程在存取集合之前鎖定此物件時, 同步處理才會生效。Synchronization is effective only if all threads lock this object before accessing the collection. 下列程式碼示範如何使用SyncRoot C#、 C++和 Visual Basic 的屬性。The following code shows the use of the SyncRoot property for C#, C++, and Visual Basic.

ICollection ic = ...;  
lock (ic.SyncRoot) {  
   // Access the collection.  
Dim ic As ICollection = ...  
SyncLock ic.SyncRoot  
   ' Access the collection.  
End SyncLock  
ICollection^ ic = ...;  
try {  
   // Access the collection.  
finally {  

擷取這個屬性的值是一種 O(1) 運算。Retrieving the value of this property is an O(1) operation.