Show / Hide Table of Contents

Class AsyncLockAcquisition

Provides a set of methods to acquire different types of asynchronous lock.

Inheritance
object
AsyncLockAcquisition
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public static class AsyncLockAcquisition

Methods

| Edit this page View Source

AcquireLockAsync<T>(T, CancellationToken)

Acquires exclusive lock associated with the given object.

Declaration
public static ValueTask<AsyncLock.Holder> AcquireLockAsync<T>(this T obj, CancellationToken token = default) where T : class
Parameters
Type Name Description
T 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.

Type Parameters
Name Description
T

The type of the object to be locked.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

AcquireLockAsync<T>(T, TimeSpan)

Acquires exclusive lock associated with the given object.

Declaration
[Obsolete("Use AcquireLockAsync(T, TimeSpan, CancellationToken) overload instead.", true)]
public static ValueTask<AsyncLock.Holder> AcquireLockAsync<T>(T obj, TimeSpan timeout) where T : class
Parameters
Type Name Description
T obj

The object to be locked.

TimeSpan timeout

The interval to wait for the lock.

Returns
Type Description
ValueTask<AsyncLock.Holder>

The acquired lock holder.

Type Parameters
Name Description
T

The type of the object to be locked.

Exceptions
Type Condition
TimeoutException

The lock cannot be acquired during the specified amount of time.

| Edit this page View Source

AcquireLockAsync<T>(T, TimeSpan, CancellationToken)

Acquires exclusive lock associated with the given object.

Declaration
public static ValueTask<AsyncLock.Holder> AcquireLockAsync<T>(this T obj, TimeSpan timeout, CancellationToken token = default) where T : class
Parameters
Type Name Description
T 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.

Type Parameters
Name Description
T

The type of the object to be locked.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

TimeoutException

The lock cannot be acquired during the specified amount of time.

| Edit this page View Source

AcquireReadLockAsync<T>(T, CancellationToken)

Acquires reader lock associated with the given object.

Declaration
public static ValueTask<AsyncLock.Holder> AcquireReadLockAsync<T>(this T obj, CancellationToken token = default) where T : class
Parameters
Type Name Description
T 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.

Type Parameters
Name Description
T

The type of the object to be locked.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

AcquireReadLockAsync<T>(T, TimeSpan)

Acquires reader lock associated with the given object.

Declaration
[Obsolete("Use AcquireReadLockAsync(T, TimeSpan, CancellationToken) overload instead.", true)]
public static ValueTask<AsyncLock.Holder> AcquireReadLockAsync<T>(T obj, TimeSpan timeout) where T : class
Parameters
Type Name Description
T obj

The object to be locked.

TimeSpan timeout

The interval to wait for the lock.

Returns
Type Description
ValueTask<AsyncLock.Holder>

The acquired lock holder.

Type Parameters
Name Description
T

The type of the object to be locked.

Exceptions
Type Condition
TimeoutException

The lock cannot be acquired during the specified amount of time.

| Edit this page View Source

AcquireReadLockAsync<T>(T, TimeSpan, CancellationToken)

Acquires reader lock associated with the given object.

Declaration
public static ValueTask<AsyncLock.Holder> AcquireReadLockAsync<T>(this T obj, TimeSpan timeout, CancellationToken token = default) where T : class
Parameters
Type Name Description
T 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.

Type Parameters
Name Description
T

The type of the object to be locked.

Exceptions
Type Condition
TimeoutException

The lock cannot be acquired during the specified amount of time.

OperationCanceledException

The operation has been canceled.

| Edit this page View Source

AcquireWriteLockAsync<T>(T, bool, CancellationToken)

Acquires reader lock associated with the given object.

Declaration
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(this T obj, bool upgrade, CancellationToken token = default) where T : class
Parameters
Type Name Description
T obj

The object to be locked.

bool upgrade

true to upgrade from read lock; otherwise, false.

CancellationToken token

The token that can be used to abort acquisition operation.

Returns
Type Description
ValueTask<AsyncLock.Holder>

The acquired lock holder.

Type Parameters
Name Description
T

The type of the object to be locked.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

AcquireWriteLockAsync<T>(T, bool, TimeSpan, CancellationToken)

Acquires reader lock associated with the given object.

Declaration
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(this T obj, bool upgrade, TimeSpan timeout, CancellationToken token = default) where T : class
Parameters
Type Name Description
T obj

The object to be locked.

bool upgrade

true to upgrade from read lock; otherwise, false.

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.

Type Parameters
Name Description
T

The type of the object to be locked.

Exceptions
Type Condition
TimeoutException

The lock cannot be acquired during the specified amount of time.

OperationCanceledException

The operation has been canceled.

| Edit this page View Source

AcquireWriteLockAsync<T>(T, CancellationToken)

Acquires reader lock associated with the given object.

Declaration
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(this T obj, CancellationToken token = default) where T : class
Parameters
Type Name Description
T 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.

Type Parameters
Name Description
T

The type of the object to be locked.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

AcquireWriteLockAsync<T>(T, TimeSpan)

Acquires writer lock associated with the given object.

Declaration
[Obsolete("Use AcquireWriteLockAsync(T, TimeSpan, CancellationToken) overload instead.", true)]
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(T obj, TimeSpan timeout) where T : class
Parameters
Type Name Description
T obj

The object to be locked.

TimeSpan timeout

The interval to wait for the lock.

Returns
Type Description
ValueTask<AsyncLock.Holder>

The acquired lock holder.

Type Parameters
Name Description
T

The type of the object to be locked.

Exceptions
Type Condition
TimeoutException

The lock cannot be acquired during the specified amount of time.

| Edit this page View Source

AcquireWriteLockAsync<T>(T, TimeSpan, CancellationToken)

Acquires reader lock associated with the given object.

Declaration
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(this T obj, TimeSpan timeout, CancellationToken token = default) where T : class
Parameters
Type Name Description
T 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.

Type Parameters
Name Description
T

The type of the object to be locked.

Exceptions
Type Condition
TimeoutException

The lock cannot be acquired during the specified amount of time.

OperationCanceledException

The operation has been canceled.

  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾