System.Threading.ReaderWriterLock.AcquireReaderLock Method

Acquires a reader lock, using an int value for the time-out.

Syntax

public void AcquireReaderLock (int millisecondsTimeout)

Parameters

millisecondsTimeout
The time-out in milliseconds.

Remarks

ReaderWriterLock.AcquireReaderLock(int) blocks if a different thread has the writer lock, or if at least one thread is waiting for the writer lock.

Note:

If the current thread already has the writer lock, no reader lock is acquired. Instead, the lock count on the writer lock is incremented. This prevents a thread from blocking on its own writer lock. The result is exactly the same as calling ReaderWriterLock.AcquireWriterLock(int), and an additional call to ReaderWriterLock.ReleaseWriterLock is required when releasing the writer lock.

AcquireReaderLock supports recursive reader-lock requests. That is, a thread can call AcquireReaderLock multiple times, which increments the lock count each time. You must call ReaderWriterLock.ReleaseReaderLock once for each time you call AcquireReaderLock. 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 reader queue. Use recursive locks with caution, to avoid blocking writer-lock requests for long periods.

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