The DistributedLock.WaitHandles package offers distributed locks based on global WaitHandles in Windows. This library only works on Windows. For example:
var @lock = new EventWaitHandleDistributedLock("MyLockName");
await using (await @lock.AcquireAsync())
{
// I have the lock!
}
- The
EventWaitHandleDistributedLock
class implements theIDistributedLock
interface. - The
WaitHandleDistributedSemaphore
class implements theIDistributedSemaphore
interface. - The
WaitHandleDistributedSynchronizationProvider
class implements theIDistributedLockProvider
andIDistributedSemaphoreProvider
interfaces.
Because they are based on global EventWaitHandle
s/Semaphore
s, these classes are used to coordinate between processes on the same machine (as opposed to across machines).
The optional abandonmentCheckCadence
argument specifies how frequently the implementation will check to see if the original holder of a lock/semaphore abandoned it without properly releasing it while waiting for it to become available. Defaults to 2s.