<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.1.2" />

Nito.AsyncEx.AsyncLock

public sealed class AsyncLock
A mutual exclusion lock that is compatible with async. Note that this lock is not recursive!
public int Id { get; }

Gets a semi-unique identifier for this asynchronous lock.

public AsyncLock()

Creates a new async-compatible mutual exclusion lock.

public IDisposable Lock(CancellationToken cancellationToken)

Synchronously acquires the lock. Returns a disposable that releases the lock when disposed. This method may block the calling thread.

public IDisposable Lock()

Synchronously acquires the lock. Returns a disposable that releases the lock when disposed. This method may block the calling thread.

public AwaitableDisposable<IDisposable> LockAsync(CancellationToken cancellationToken)

Asynchronously acquires the lock. Returns a disposable that releases the lock when disposed.

public AwaitableDisposable<IDisposable> LockAsync()

Asynchronously acquires the lock. Returns a disposable that releases the lock when disposed.