Class AsyncLockAcquisition
Provides a set of methods to acquire different types of asynchronous lock.
Inherited Members
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public static class AsyncLockAcquisition
Methods
| Edit this page View SourceAcquireLockAsync(object, CancellationToken)
Acquires exclusive lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireLockAsync(object obj, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to be locked. |
| CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
| Type | Description |
|---|---|
| ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Exceptions
| Type | Condition |
|---|---|
| OperationCanceledException | The operation has been canceled. |
AcquireLockAsync(object, TimeSpan, CancellationToken)
Acquires exclusive lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireLockAsync(object obj, TimeSpan timeout, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to be locked. |
| TimeSpan | timeout | The interval to wait for the lock. |
| CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
| Type | Description |
|---|---|
| ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Exceptions
| Type | Condition |
|---|---|
| OperationCanceledException | The operation has been canceled. |
| TimeoutException | The lock cannot be acquired during the specified amount of time. |
AcquireReadLockAsync(object, CancellationToken)
Acquires reader lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireReadLockAsync(object obj, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to be locked. |
| CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
| Type | Description |
|---|---|
| ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Exceptions
| Type | Condition |
|---|---|
| OperationCanceledException | The operation has been canceled. |
AcquireReadLockAsync(object, TimeSpan, CancellationToken)
Acquires reader lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireReadLockAsync(object obj, TimeSpan timeout, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to be locked. |
| TimeSpan | timeout | The interval to wait for the lock. |
| CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
| Type | Description |
|---|---|
| ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Exceptions
| Type | Condition |
|---|---|
| TimeoutException | The lock cannot be acquired during the specified amount of time. |
| OperationCanceledException | The operation has been canceled. |
AcquireWriteLockAsync(object, bool, CancellationToken)
Acquires reader lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync(object obj, bool upgrade, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to be locked. |
| bool | upgrade | |
| CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
| Type | Description |
|---|---|
| ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Exceptions
| Type | Condition |
|---|---|
| OperationCanceledException | The operation has been canceled. |
AcquireWriteLockAsync(object, bool, TimeSpan, CancellationToken)
Acquires reader lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync(object obj, bool upgrade, TimeSpan timeout, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to be locked. |
| bool | upgrade | |
| TimeSpan | timeout | The interval to wait for the lock. |
| CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
| Type | Description |
|---|---|
| ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Exceptions
| Type | Condition |
|---|---|
| TimeoutException | The lock cannot be acquired during the specified amount of time. |
| OperationCanceledException | The operation has been canceled. |
AcquireWriteLockAsync(object, CancellationToken)
Acquires reader lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync(object obj, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to be locked. |
| CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
| Type | Description |
|---|---|
| ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Exceptions
| Type | Condition |
|---|---|
| OperationCanceledException | The operation has been canceled. |
AcquireWriteLockAsync(object, TimeSpan, CancellationToken)
Acquires reader lock associated with the given object.
Declaration
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync(object obj, TimeSpan timeout, CancellationToken token = default)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to be locked. |
| TimeSpan | timeout | The interval to wait for the lock. |
| CancellationToken | token | The token that can be used to abort acquisition operation. |
Returns
| Type | Description |
|---|---|
| ValueTask<AsyncLock.Holder> | The acquired lock holder. |
Exceptions
| Type | Condition |
|---|---|
| TimeoutException | The lock cannot be acquired during the specified amount of time. |
| OperationCanceledException | The operation has been canceled. |