Method EnterWriteGuardAsync
EnterWriteGuardAsync(CancellationToken)
Asynchronously enters the lock in write mode and returns a guard that leaves it when it is disposed.
Declaration
public ValueTask<AsyncWriteGuard> EnterWriteGuardAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | A token that cancels the wait. |
Returns
| Type | Description |
|---|---|
| ValueTask<AsyncWriteGuard> | A task that contains a guard that entered the lock. The task has already completed, and nothing is allocated, when the lock is entered without waiting. |
Remarks
The call waits while the lock is held in either mode and while writers that arrived earlier are waiting. The lock is not reentrant, so entering it again while the caller holds it can wait forever; see AsyncReadWriteLockPreference.
Await the returned task once. For a time limit, use TryEnterWriteGuardAsync(TimeSpan, CancellationToken). A limit put on the task
itself, such as with WaitAsync, ends the await but not the wait, and a hold that the lock grants after it is never released.
Exceptions
| Type | Condition |
|---|---|
| OperationCanceledException |
|