DotNext.Threading by Roman Sakno

<PackageReference Include="DotNext.Threading" Version="3.2.1" />

 AsyncExclusiveLock

Represents asynchronous mutually exclusive lock.
public bool IsLockHeld { get; }

Indicates that exclusive lock taken.

public Task AcquireAsync(TimeSpan timeout, CancellationToken token = default)

Enters the lock in exclusive mode asynchronously.

Enters the lock in exclusive mode asynchronously.

Disposes this lock asynchronously and gracefully.

public void Release()

Releases previously acquired exclusive lock.

public bool TryAcquire()

Attempts to obtain exclusive lock synchronously without blocking caller thread.

public Task<bool> TryAcquireAsync(TimeSpan timeout, CancellationToken token)

Tries to enter the lock in exclusive mode asynchronously, with an optional time-out.

public Task<bool> TryAcquireAsync(TimeSpan timeout)

Tries to enter the lock in exclusive mode asynchronously, with an optional time-out.