Dictionary<TKey,TValue>.ICollection.IsSynchronized Dictionary<TKey,TValue>.ICollection.IsSynchronized Dictionary<TKey,TValue>.ICollection.IsSynchronized Property

定義

取得值,這個值會指出 ICollection 的存取是否同步 (具備安全執行緒)。Gets a value that indicates whether access to the ICollection is synchronized (thread safe).

property bool System::Collections::ICollection::IsSynchronized { bool get(); };
bool System.Collections.ICollection.IsSynchronized { get; }
 ReadOnly Property IsSynchronized As Boolean Implements ICollection.IsSynchronized

屬性值

如果 true 的存取為同步 (安全執行緒),則為 ICollection,否則為 falsetrue if access to the ICollection is synchronized (thread safe); otherwise, false. Dictionary<TKey,TValue> 的預設實作中,這個屬性永遠會傳回 falseIn the default implementation of Dictionary<TKey,TValue>, this property always returns false.

實作

備註

System.Collections.Generic 命名空間中集合的預設實作未同步處理。Default implementations of collections in the System.Collections.Generic namespace are not synchronized.

透過集合進行列舉在本質上並非安全執行緒程序。Enumerating through a collection is intrinsically not a thread-safe procedure. 即使集合已同步處理,其他執行緒仍然可以修改集合,這可能會導致列舉值擲回例外狀況。Even when a collection is synchronized, other threads can still modify the collection, which can cause the enumerator to throw an exception. 若要保證列舉過程的執行緒安全,您可以在整個列舉過程中鎖定集合,或攔截由其他執行緒的變更所造成的例外狀況。To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.

屬性會傳回可用來同步存取的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 the object before accessing the collection.

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

適用於

另請參閱