Class AsyncExclusiveLock
Represents asynchronous mutually exclusive lock.
Implements
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncExclusiveLock : QueuedSynchronizer, ISynchronizer
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 SourceAcquire(CancellationToken)
Enters the lock in exclusive mode asynchronously.
Declaration
public Task Acquire(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. |
Acquire(TimeSpan)
Enters the lock in exclusive mode asynchronously.
Declaration
public Task Acquire(TimeSpan timeout)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | The interval to wait for the lock. |
Returns
| Type | Description |
|---|---|
| Task | The task representing lock acquisition operation. |
Release()
Releases previously acquired exclusive lock.
Declaration
public void Release()
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. |
TryAcquire(TimeSpan)
Tries to enter the lock in exclusive mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryAcquire(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. |
TryAcquire(TimeSpan, CancellationToken)
Tries to enter the lock in exclusive mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryAcquire(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. |