Show / Hide Table of Contents

Class AsyncExclusiveLock

Represents asynchronous mutually exclusive lock.

Inheritance
Object
QueuedSynchronizer
AsyncExclusiveLock
Implements
ISynchronizer
IAsyncDisposable
Inherited Members
QueuedSynchronizer.ISynchronizer.HasWaiters
QueuedSynchronizer.CancelSuspendedCallers(CancellationToken)
QueuedSynchronizer.Dispose(Boolean)
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncExclusiveLock : QueuedSynchronizer, ISynchronizer, IAsyncDisposable

Properties

| Improve this Doc View Source

IsLockHeld

Indicates that exclusive lock taken.

Declaration
public bool IsLockHeld { get; }
Property Value
Type Description
Boolean

Methods

| Improve this Doc View Source

AcquireAsync(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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

Implements

ISynchronizer
System.IAsyncDisposable

Extension Methods

AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, CancellationToken)
ObjectExtensions.GetUserData<T>(T)
ObjectExtensions.IsOneOf<T>(T, IEnumerable<T>)
ObjectExtensions.IsOneOf<T>(T, T[])
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>, out TResult1, out TResult2)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>, out TResult1, out TResult2)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>)
ObjectExtensions.As<T>(T)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
ExpressionBuilder.Const<T>(T)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX