SynchronizedDictionaryAcquireWriteLock Method (Int32) |
Namespace: Tangosol.Util.Collections
public bool AcquireWriteLock( int timeout )
Only a single thread can hold the write lock at any given time, and no other threads will be able to acquire either a read lock or a write lock until the write lock is released.
This method should always be used in combination with a ReleaseWriteLock method in the following manner:
if (dict.AcquireWriteLock(timeout)) { try { // access dictionary } finally { dict.ReleaseWriteLock(); } }
It is entirely up to you how to handle the case when the AcquireWriteLock method returns false. For example, you can ignore the fact, throw an exception, or retry the operation by placing the code above within a loop.