DotNext.Threading by Roman Sakno

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

 AsyncSharedLock

Represents a lock that can be acquired in exclusive or weak mode.
public long ConcurrencyLevel { get; }

Gets the maximum number of locks that can be obtained simultaneously.

public bool IsLockHeld { get; }

Indicates that the lock is acquired in exclusive or shared mode.

public long RemainingCount { get; }

Gets the number of shared locks that can be acquired.

public AsyncSharedLock(long concurrencyLevel)

Initializes a new shared lock.

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

Entres the lock asynchronously.

public Task AcquireAsync(bool strongLock, CancellationToken token)

Entres the lock asynchronously.

Disposes this lock asynchronously and gracefully.

public void Downgrade()

Releases the acquired weak lock or downgrade exclusive lock to the weak lock.

public void Release()

Release the acquired lock.

public bool TryAcquire(bool strongLock)

Attempts to obtain lock synchronously without blocking caller thread.

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

Attempts to enter the lock asynchronously, with an optional time-out.

public Task<bool> TryAcquireAsync(bool strongLock, TimeSpan timeout)

Attempts to enter the lock asynchronously, with an optional time-out.