SafeDictionaryTKey, TValueGetRealCount Method |
Namespace: CMS.Base
The operation is executed on a snapshot of the dictionary. Therefore, the dictionary's content can be changed by other threads while computing the result. If you want to make sure the dictionary's content does not change while computing the real count, use the SyncRoot.
Important: When the dictionary uses weak references, no lock can guarantee you that no item has been released from the memory while computing the real count.
lock (dictionary.SyncRoot) { int realCount = dictionary.GetRealCount(); // The realCount corresponds to current dictionary's state only when weak references are NOT used // Otherwise, some entries might have been released from the memory regardless of the lock }