SafeDictionaryTKey, TValueSyncRoot Property |
Namespace: CMS.Base
public override Object SyncRoot { get; }
Utilize this property when you need to perform multiple dictionary operations as a single atomic operation, or when you need to enumerate the entries.
Obtaining a lock does not prevent all other threads from read operations, since most read operations do not need to use locking.
lock (dictionary.SyncRoot) { foreach (var entry in dictionary) { // Perform some operation // Try to avoid time consuming operations to release the lock as soon as possible // No other thread can modify the dictionary when it is locked using the SyncRoot property // However, read access does not require locking, therefore any other thread can still read the dictionary's content } }