System.Threading.ReaderWriterLockSlim.TryEnterReadLock Method

Tries to enter the lock in read mode, with an optional integer time-out.

Syntax

public bool TryEnterReadLock (int millisecondsTimeout)

Parameters

millisecondsTimeout
The number of milliseconds to wait, or -1 (Timeout.Infinite) to wait indefinitely.

Returns

true if the calling thread entered read mode, otherwise, false.

Remarks

If millisecondsTimeout is 0 (zero), this method checks the lock state and returns false immediately if the desired state is unavailable.

Multiple threads can enter read mode at the same time.

If one or more threads are waiting to enter write mode, a thread that calls the ReaderWriterLockSlim.TryEnterReadLock(int) method blocks until those threads have either timed out or entered write mode and then exited from it, or until the calling thread's own time-out interval expires.

Note:

If a lock allows recursion, a thread that has entered the lock in read mode can enter read mode recursively, even if other threads are waiting to enter write mode.

One thread can be in upgradeable mode while other threads are in read mode. If additional threads are waiting to enter upgradeable mode, and there are no threads waiting to enter write mode, threads that call the ReaderWriterLockSlim.TryEnterReadLock(int) method enter read mode immediately and do not block.

Requirements

Namespace: System.Threading
Assembly: System.Core (in System.Core.dll)
Assembly Versions: 4.0.0.0