Class AsyncLock
A lock that allows for async based operations and returns a IDisposable which allows for unlocking.
public sealed class AsyncLock : IDisposable
- Inheritance
-
AsyncLock
- Implements
- Extension Methods
Remarks
Straight-up thieved from http://www.hanselman.com/blog/ComparingTwoTechniquesInNETAsynchronousCoordinationPrimitives.aspx and all credit to that article.
Constructors
AsyncLock()
Initializes a new instance of the AsyncLock class.
public AsyncLock()
Methods
Dispose()
public void Dispose()
LockAsync(CancellationToken)
Performs a lock which will be either released when the cancellation token is cancelled, or the returned disposable is disposed.
public Task<IDisposable?> LockAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenA cancellation token which allows for release of the lock.
Returns
- Task<IDisposable>
A disposable which when Disposed will release the lock.