DotNext by Roman Sakno

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

 Lock

public struct Lock : IDisposable, IEquatable<Lock>
Represents unified representation monitor lock, read lock, write lock or upgradable read lock.
public static Lock Monitor(object obj)

Creates monitor-based lock control object but doesn't acquire 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)

Creates read lock but doesn't acquire it.

public static Lock Semaphore(SemaphoreSlim semaphore)

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

Creates upgradable read lock but doesn't acquire.

public static Lock WriteLock(ReaderWriterLockSlim rwLock)

Creates write lock but doesn't acquire it.

public void Acquire()

Acquires lock.

public void Dispose()

Releases acquired lock.

public bool Equals(ref Lock other)

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

public bool TryAcquire()

Attempts to acquire lock.

public bool TryAcquire(TimeSpan timeout)

Attempts to acquire lock.