SafeDictionaryTKey, TValueGetRealCount Method |
Namespace: CMS.Base
The dictionary's content can be changed by other threads after computing the result. If you want to make sure the dictionary's content does not change until the real count is used, 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 }