Async lock context helper.
readonly? ILogger logger
An optional ILogger to write to.
readonly SemaphoreSlim lockedSemaphore
The locked SemaphoreSlim.
SemaphoreSlimContext(SemaphoreSlim lockedSemaphore, ILogger? logger)
Initializes a new instance of the SemaphoreSlimContext class.
static async ValueTask< SemaphoreSlimContext > Lock(SemaphoreSlim semaphore, CancellationToken cancellationToken, ILogger? logger=null)
Asyncronously locks a semaphore .
static ? SemaphoreSlimContext TryLock(SemaphoreSlim semaphore, ILogger? logger, out bool locked)
Asyncronously attempts to lock a semaphore .
void Dispose()
Release the lock on lockedSemaphore.