Language

ReentrantSemaphore.ExecuteAsync Method

Definition

Overloads

Name Description
ExecuteAsync(Func<Task>, CancellationToken)

Executes a given operation within the semaphore.

ExecuteAsync<T>(Func<ValueTask<T>>, CancellationToken)

Executes a given operation within the semaphore.

ExecuteAsync(Func<Task>, CancellationToken)

Executes a given operation within the semaphore.

public abstract System.Threading.Tasks.Task ExecuteAsync(Func<System.Threading.Tasks.Task> operation, System.Threading.CancellationToken cancellationToken = default);
abstract member ExecuteAsync : Func<System.Threading.Tasks.Task> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public MustOverride Function ExecuteAsync (operation As Func(Of Task), Optional cancellationToken As CancellationToken = Nothing) As Task

Parameters

operation
Func<Task>

The delegate to invoke once the semaphore is entered. If a JoinableTaskContext was supplied to the constructor, this delegate will execute on the main thread if this is invoked on the main thread, otherwise it will be invoked on the threadpool. When no JoinableTaskContext is supplied to the constructor, this delegate will execute on the caller's context.

cancellationToken
CancellationToken

A cancellation token.

Returns

A task that completes with the result of operation, after the semaphore has been exited.

Applies to

ExecuteAsync<T>(Func<ValueTask<T>>, CancellationToken)

Executes a given operation within the semaphore.

public abstract System.Threading.Tasks.ValueTask<T> ExecuteAsync<T>(Func<System.Threading.Tasks.ValueTask<T>> operation, System.Threading.CancellationToken cancellationToken = default);
abstract member ExecuteAsync : Func<System.Threading.Tasks.ValueTask<'T>> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'T>
Public MustOverride Function ExecuteAsync(Of T) (operation As Func(Of ValueTask(Of T)), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of T)

Type Parameters

T

The type of value returned by the operation.

Parameters

operation
Func<ValueTask<T>>

The delegate to invoke once the semaphore is entered. If a JoinableTaskContext was supplied to the constructor, this delegate will execute on the main thread if this is invoked on the main thread, otherwise it will be invoked on the threadpool. When no JoinableTaskContext is supplied to the constructor, this delegate will execute on the caller's context.

cancellationToken
CancellationToken

A cancellation token.

Returns

A task that completes with the result of operation, after the semaphore has been exited.

Exceptions

Thrown when reentrancy is detected and not allowed based due to NotAllowed being provided to the constructor. This happens when code that already holds the semaphore calls code that attempts to again enter the semaphore. When the called code is not awaited on by the caller, it may be appropriate to suppress this reentrancy detection for the method that is called in a fire-and-forget fashion. To suppress this exception for that specific case while preserving overall protection, use SuppressRelevance().

Applies to