Method TryEnterReadGuard
TryEnterReadGuard()
Tries to enter the lock in read mode without waiting and returns a guard whose IsEntered property says whether it did. Disposing the guard leaves the lock, or does nothing if the lock was not entered.
Declaration
public AsyncReadGuard TryEnterReadGuard()
Returns
| Type | Description |
|---|---|
| AsyncReadGuard |
Remarks
The lock is entered if a call that waits would have entered it without waiting: it is not held in write mode and, unless the lock prefers readers, no writer is waiting. The call allocates nothing.
The lock is not reentrant, but this call never waits for it. If the caller holds the lock in write mode, the call returns a guard that did not enter it. If the caller holds it in read mode, the call can take a second read hold, which its own guard releases.
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | The lock is already held in read mode by the largest number of holds it can count (2^29). |