Gets an object that can be used to synchronize access to the Dictionary.
[Visual Basic] Overridable Public ReadOnly Property SyncRoot As Object [C#] public object SyncRoot {virtual get;} [C++] public: __property virtual Object* get_SyncRoot(); [JScript] public function get SyncRoot() : Object;
An object that can be used to synchronize access to the Dictionary.
The root object for a Dictionary is used when performing synchronized operations on the Dictionary. Instead of synchronizing directly on a Dictionary, program code should always synchronize on the root of the Dictionary. This ensures proper operation of dictionaries that are derived from other objects; proper synchronization is maintained with other threads that might be simultaneously modifying the Dictionary object.
In the following example, the Message object exposes a set of properties as a Dictionary. By synchronizing on the root of d (which will return a reference to the Message object), proper synchronization is maintained with other threads that might be simultaneously modifying the Message object.
Message m = ...; Dictionary d = m->GetProperties(); synchronized (d->GetRoot()) { String sender = (String)d->Get("Sender"); byte[] bytes = (byte[])d->Get("Bytes"); ... }
Dictionary Class | Dictionary Members | System.Collections Namespace | IsSynchronized | Synchronized