Collapse All Expand All

C#

Oracle® Coherence .NET API Reference
SynchronizedDictionary..::.AcquireWriteLock Method (Int64)
SynchronizedDictionary Class See Also Send Feedback

Oracle® Coherence .NET API Reference Release 3.6
E15727-01
Acquire a write lock.

Namespace: Tangosol.Util.Collections
Assembly: Coherence (in Coherence.dll) Version: 3.6.0.0 (3.6.0.0)

# Syntax

C#
    public bool AcquireWriteLock(
    	long timeout
    )

#### Parameters

timeout
  Type: System..::.Int64
  Timeout in milliseconds.

#### Return Value

[Missing <returns> documentation for "M:Tangosol.Util.Collections.SynchronizedDictionary.AcquireWriteLock(System.Int64)"]

# Remarks

This method will attempt to acquire a write lock for up to timeout milliseconds, and will return a boolean value specifying whether or not the lock was acquired successfully.

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:
CopyC#

    if (dict.AcquireWriteLock(timeout))
    {
        try
        {
            // access dictionary
        }
        finally
        {
            dict.ReleaseWriteLock();
        }
    }

This will ensure that the dictionary is not accessed unless the lock was acquired successfully, and that the lock is released properly even if an exception is thrown by the code within the try block.

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.

# See Also

SynchronizedDictionary Class
AcquireWriteLock Overload
Tangosol.Util.Collections Namespace
SynchronizedDictionary..::.AcquireWriteLock()()()
SynchronizedDictionary..::.ReleaseWriteLock()()()