Click or drag to resize
SafeDictionaryTKey, TValueGetRealCount Method
Gets the real count of the objects in the dictionary.

Namespace: CMS.Base
Assembly: CMS.Base (in CMS.Base.dll) Version: 9.0.0
Syntax
C#
public int GetRealCount()

Return Value

Type: Int32
Remarks

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.

Examples
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
}
See Also