DotNext.Threading by .NET Foundation and Contributors

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

 AsyncLock

Unified representation of asynchronous exclusive lock, semaphore lock, read lock, write lock or upgradeable read lock.
public struct Holder : IDisposable

Represents acquired asynchronous lock.

public static AsyncLock Exclusive()

Creates exclusive asynchronous lock but doesn't acquire it.

Wraps exclusive lock into the unified representation of asynchronous lock.

public static AsyncLock Exclusive(AsyncSharedLock lock)

Creates strong (exclusive) lock but doesn't acquire it.

public static bool op_Equality(ref AsyncLock first, ref AsyncLock second)

Determines whether two locks are the same.

public static bool op_Inequality(ref AsyncLock first, ref AsyncLock second)

Determines whether two locks are not the same.

public static AsyncLock ReadLock(AsyncReaderWriterLock rwLock, bool upgradeable)

Creates read lock but doesn't acquire it.

public static AsyncLock Semaphore(SemaphoreSlim semaphore)

Wraps semaphore instance into the unified representation of the lock.

public static AsyncLock Semaphore(int initialCount, int maxCount)

Creates semaphore-based lock but doesn't acquire the lock.

public static AsyncLock Weak(AsyncSharedLock lock)

Creates weak lock but doesn't acquire it.

Creates write lock but doesn't acquire it.

Acquires the lock asynchronously.

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

Acquires the lock asynchronously.

public void Dispose()

Destroy this lock and dispose underlying lock object if it is owned by the given lock.

Destroy this lock and asynchronously dispose underlying lock object if it is owned by the given lock.

public bool Equals(AsyncLock other)

Determines whether this lock object is the same as other lock.

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

Tries to acquire the lock asynchronously.

public Task<Holder> TryAcquireAsync(TimeSpan timeout, CancellationToken token = default)

Tries to acquire the lock asynchronously.

Tries to acquire lock asynchronously.