DotNext by .NET Foundation and Contributors

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

 Lock

public struct Lock : IDisposable, IEquatable<Lock>
Unified representation of monitor lock, semaphore lock, read lock, write lock or upgradeable read lock.
public struct Holder

Represents acquired lock holder.

public static Lock Monitor(object obj)

Creates monitor-based lock control object but doesn't acquire the lock.

public static Lock Monitor(object obj, bool useSpinWait)

Creates monitor-based lock control object but doesn't acquire the lock.

public static Lock Monitor()

Creates exclusive lock.

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

Determines whether two locks are the same.

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

Determines whether two locks are not the same.

public static Lock ReadLock(ReaderWriterLockSlim rwLock, bool upgradeable)

Creates read lock but doesn't acquire it.

public static Lock Semaphore(SemaphoreSlim semaphore)

Wraps semaphore instance into the unified representation of the lock.

public static Lock Semaphore(int initialCount, int maxCount)

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

public static Lock WriteLock(ReaderWriterLockSlim rwLock)

Creates write lock but doesn't acquire it.

public Holder Acquire()

Acquires lock.

public Holder Acquire(TimeSpan timeout)

Acquires lock.

public void Dispose()

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

public bool Equals(Lock other)

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

public bool TryAcquire(out Holder holder)

Attempts to acquire lock.

public bool TryAcquire(TimeSpan timeout, out Holder holder)

Attempts to acquire lock.