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: 13.0.131
Syntax
C#
public int GetRealCount()

Return Value

Type: Int32
Remarks

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.

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