Class AsyncMutex
Represents a source of a fair asynchronous mutex primitive.
public sealed class AsyncMutex
- Inheritance
-
AsyncMutex
- Inherited Members
- Extension Methods
Remarks
Lock is not reentrant.
Constructors
AsyncMutex()
Creates a new AsyncMutex instance.
public AsyncMutex()
Properties
Participants
Returns the total number of lock participants, which includes current lock holder and all waiters.
public int Participants { get; }
Property Value
Methods
EnterAsync(CancellationToken)
Asynchronously acquires an exclusive lock from this mutex.
public ValueTask<AsyncMutexToken> EnterAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenOptional CancellationToken that can be used to cancel pending mutex acquisition.
Returns
- ValueTask<AsyncMutexToken>
New ValueTask<TResult> instance which returns an AsyncMutexToken value.
Exceptions
- OperationCanceledException
When provided
cancellationTokenwas cancelled before the lock was acquired.
TrimExcess()
Attempts to discard unused resources.
public void TrimExcess()
TryEnter(out bool)
Attempts to synchronously acquire an exclusive lock from this mutex.
public AsyncMutexToken TryEnter(out bool entered)
Parameters
enteredboolout parameter which specifies whether the lock was acquired.
Returns
- AsyncMutexToken
New AsyncMutexToken value. When
enteredis false, then returned instanced will be a default value.