RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
DataStoreParameterCollection.SyncRoot Property

Returns the SyncRoot of the collection.

Pascal
property SyncRoot: object;
C++
__property object SyncRoot;

Each collection, whether a list, array, or hashtable, has a SyncRoot. Each collection contains a single root and multiple nodes or branches below that root. When multiple threads access a collection, they might update values in the collection. When you want to use the values of the collection, your thread might not have an accurate and current snapshot of the collection that has been modified numerous times since you first retrieved it.  

Perform the synchronization on the SyncRoot, not on the collection directly. Synchronization, starting at the SyncRoot, ripples the updates throughout the tree to give you an accurate collection. Nonetheless, even when the collection is synchronized, other threads can modify the collection, which then causes the enumerator to throw an exception. You might consider trapping the exception to make sure that you know when your collection is modified by another thread. 

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!