Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ReaderWriterLock::AcquireReaderLock Method (TimeSpan)

 

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

Namespace:   System.Threading
Assembly:  mscorlib (in mscorlib.dll)

public:
void AcquireReaderLock(
	TimeSpan timeout
)

Parameters

timeout
Type: System::TimeSpan

A TimeSpan specifying the time-out period.

Exception Condition
ApplicationException

timeout expires before the lock request is granted.

ArgumentOutOfRangeException

timeout specifies a negative value other than -1 milliseconds.

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

System_CAPS_noteNote

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 AcquireWriterLock, and an additional call to 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 ReleaseReaderLock once for each time you call AcquireReaderLock. Alternatively, you can call 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 ReaderWriterLock.

.NET Framework
Available since 1.1
Return to top
Show:
© 2017 Microsoft