<PackageReference Include="Nito.AsyncEx.Tasks" Version="5.1.1" />

Nito.AsyncEx.SemaphoreSlimExtensions

public static class SemaphoreSlimExtensions
Provides extension methods for SemaphoreSlim.
public static IDisposable Lock(this SemaphoreSlim this, CancellationToken cancellationToken)

Synchronously waits on the semaphore, and returns a disposable that releases the semaphore when disposed, thus treating this semaphore as a "multi-lock".

public static IDisposable Lock(this SemaphoreSlim this)

Synchronously waits on the semaphore, and returns a disposable that releases the semaphore when disposed, thus treating this semaphore as a "multi-lock".

public static AwaitableDisposable<IDisposable> LockAsync(this SemaphoreSlim this, CancellationToken cancellationToken)

Asynchronously waits on the semaphore, and returns a disposable that releases the semaphore when disposed, thus treating this semaphore as a "multi-lock".

Asynchronously waits on the semaphore, and returns a disposable that releases the semaphore when disposed, thus treating this semaphore as a "multi-lock".