System.Threading.ReaderWriterLock.AcquireWriterLock Method

Acquires the writer lock, using a TimeSpan value for the time-out.

Syntax

public void AcquireWriterLock (TimeSpan timeout)

Parameters

timeout
The TimeSpan specifying the time-out period.

Remarks

This method blocks if another thread has a reader lock or writer lock. For a description of the way the writer lock alternates with multiple concurrent reader locks, see the System.Threading.ReaderWriterLock class.

A thread that already has a reader lock can acquire the writer lock in one of two ways: by releasing the reader lock before calling ReaderWriterLock.AcquireWriterLock(int), or by calling ReaderWriterLock.UpgradeToWriterLock(int).

Note:

If a thread calls AcquireWriterLock while it still has a reader lock, it will block on its own reader lock; if an infinite time-out is specified, the thread will deadlock. To avoid such deadlocks, use ReaderWriterLock.IsReaderLockHeld to determine whether the current thread already has a reader lock.

AcquireWriterLock supports recursive writer-lock requests. That is, a thread can call AcquireWriterLock multiple times, which increments the lock count each time. You must call ReaderWriterLock.ReleaseWriterLock once for each time you call AcquireWriterLock. Alternatively, you can call ReaderWriterLock.ReleaseLock to reduce the lock count to zero immediately.

Recursive lock requests are always granted immediately, without placing the requesting thread in the writer queue.

For valid time-out values, see System.Threading.ReaderWriterLock.

Requirements

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0