NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Dictionary.SyncRoot

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;

Property Value

An object that can be used to synchronize access to the Dictionary.

Remarks

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.

Example

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");
  ...
}

See Also

Dictionary Class | Dictionary Members | System.Collections Namespace | IsSynchronized | Synchronized