Threading Threading
Threading Threading
DocFX + Singulink = ♥

Search Results for

    Method TryEnterReadGuardAsync

    TryEnterReadGuardAsync(TimeSpan, CancellationToken)

    Asynchronously tries to enter the lock in read mode within a time limit 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 ValueTask<AsyncReadGuard> TryEnterReadGuardAsync(TimeSpan timeout, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    TimeSpan timeout

    The time to wait for the lock: zero to not wait, or InfiniteTimeSpan to wait without a limit. At most MaxValue milliseconds. A time that is not a whole number of milliseconds is rounded up to the next whole millisecond.

    CancellationToken cancellationToken

    A token that cancels the wait.

    Returns
    Type Description
    ValueTask<AsyncReadGuard>

    A task that contains the guard. The task has already completed, and nothing is allocated, when the lock is entered without waiting or timeout is zero.

    Remarks

    The call waits while the lock is held in write mode and, unless the lock prefers readers, while a writer is waiting. An exception that the time provider throws when it creates the timer of the time limit is in the returned task. The lock is not reentrant, so entering it again while the caller holds it can wait until the time limit passes, or forever without one; see AsyncReadWriteLockPreference.

    Await the returned task once, and give the time limit to this call. 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
    ArgumentOutOfRangeException

    timeout is negative and is not InfiniteTimeSpan, or is more than MaxValue milliseconds. This is the only exception that is thrown by the call and not by the returned task.

    OperationCanceledException

    cancellationToken was canceled before the lock was entered or the time limit passed.

    InvalidOperationException

    The lock is already held in read mode by the largest number of holds it can count (2^29).

    © Singulink. All rights reserved.