Class AsyncExclusiveLock
Represents asynchronous mutually exclusive lock.
Inherited Members
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncExclusiveLock : QueuedSynchronizer, ISynchronizer, IAsyncDisposable
Properties
| Improve this Doc View SourceIsLockHeld
Indicates that exclusive lock taken.
Declaration
public bool IsLockHeld { get; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
| Improve this Doc View SourceAcquireAsync(CancellationToken)
Enters the lock in exclusive mode asynchronously.
Declaration
public Task AcquireAsync(CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | token | The token that can be used to abort lock acquisition. |
Returns
Type | Description |
---|---|
Task | The task representing lock acquisition operation. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Time-out value is negative. |
ObjectDisposedException | This object has been disposed. |
AcquireAsync(TimeSpan, CancellationToken)
Enters the lock in exclusive mode asynchronously.
Declaration
public Task AcquireAsync(TimeSpan timeout, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | timeout | The interval to wait for the lock. |
CancellationToken | token | The token that can be used to abort lock acquisition. |
Returns
Type | Description |
---|---|
Task | The task representing lock acquisition operation. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Time-out value is negative. |
ObjectDisposedException | This object has been disposed. |
TimeoutException | The lock cannot be acquired during the specified amount of time. |
DisposeAsync()
Disposes this lock asynchronously and gracefully.
Declaration
public ValueTask DisposeAsync()
Returns
Type | Description |
---|---|
ValueTask | The task representing graceful shutdown of this lock. |
Remarks
If this lock is not acquired then the method just completes synchronously. Otherwise, it waits for calling of Release() method.
Release()
Releases previously acquired exclusive lock.
Declaration
public void Release()
Exceptions
Type | Condition |
---|---|
SynchronizationLockException | The caller has not entered the lock. |
ObjectDisposedException | This object has been disposed. |
TryAcquire()
Attempts to obtain exclusive lock synchronously without blocking caller thread.
Declaration
public bool TryAcquire()
Returns
Type | Description |
---|---|
Boolean | true if lock is taken successfuly; otherwise, false. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This object has been disposed. |
TryAcquireAsync(TimeSpan)
Tries to enter the lock in exclusive mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryAcquireAsync(TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | timeout | The interval to wait for the lock. |
Returns
Type | Description |
---|---|
Task<Boolean> | true if the caller entered exclusive mode; otherwise, false. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Time-out value is negative. |
ObjectDisposedException | This object has been disposed. |
TryAcquireAsync(TimeSpan, CancellationToken)
Tries to enter the lock in exclusive mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryAcquireAsync(TimeSpan timeout, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | timeout | The interval to wait for the lock. |
CancellationToken | token | The token that can be used to abort lock acquisition. |
Returns
Type | Description |
---|---|
Task<Boolean> | true if the caller entered exclusive mode; otherwise, false. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Time-out value is negative. |
ObjectDisposedException | This object has been disposed. |