ExecutionStrategy.ExecuteAsync Method

Definition

Overloads

ExecuteAsync<TState,TResult>(TState, Func<DbContext,TState,CancellationToken, Task<TResult>>, Func<DbContext,TState,CancellationToken,Task<ExecutionResult<TResult>>>, CancellationToken)

Executes the specified asynchronous operation and returns the result.

ExecuteAsync<TState,TResult>(Func<TState,CancellationToken,Task<TResult>>, Func<TState,CancellationToken,Task<ExecutionResult<TResult>>>, TState, CancellationToken)

Executes the specified asynchronous operation and returns the result.

ExecuteAsync<TState,TResult>(TState, Func<DbContext,TState,CancellationToken, Task<TResult>>, Func<DbContext,TState,CancellationToken,Task<ExecutionResult<TResult>>>, CancellationToken)

Executes the specified asynchronous operation and returns the result.

public virtual System.Threading.Tasks.Task<TResult> ExecuteAsync<TState,TResult> (TState state, Func<Microsoft.EntityFrameworkCore.DbContext,TState,System.Threading.CancellationToken,System.Threading.Tasks.Task<TResult>> operation, Func<Microsoft.EntityFrameworkCore.DbContext,TState,System.Threading.CancellationToken,System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.Storage.ExecutionResult<TResult>>> verifySucceeded, System.Threading.CancellationToken cancellationToken = default);
public virtual System.Threading.Tasks.Task<TResult> ExecuteAsync<TState,TResult> (TState state, Func<Microsoft.EntityFrameworkCore.DbContext,TState,System.Threading.CancellationToken,System.Threading.Tasks.Task<TResult>> operation, Func<Microsoft.EntityFrameworkCore.DbContext,TState,System.Threading.CancellationToken,System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.Storage.ExecutionResult<TResult>>>? verifySucceeded, System.Threading.CancellationToken cancellationToken = default);
abstract member ExecuteAsync : 'State * Func<Microsoft.EntityFrameworkCore.DbContext, 'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<'Result>> * Func<Microsoft.EntityFrameworkCore.DbContext, 'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.Storage.ExecutionResult<'Result>>> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
override this.ExecuteAsync : 'State * Func<Microsoft.EntityFrameworkCore.DbContext, 'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<'Result>> * Func<Microsoft.EntityFrameworkCore.DbContext, 'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.Storage.ExecutionResult<'Result>>> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
Public Overridable Function ExecuteAsync(Of TState, TResult) (state As TState, operation As Func(Of DbContext, TState, CancellationToken, Task(Of TResult)), verifySucceeded As Func(Of DbContext, TState, CancellationToken, Task(Of ExecutionResult(Of TResult))), Optional cancellationToken As CancellationToken = Nothing) As Task(Of TResult)

Type Parameters

TState

The type of the state.

TResult

The result type of the Task<TResult> returned by operation.

Parameters

state
TState

The state that will be passed to the operation.

operation
Func<DbContext,TState,CancellationToken,Task<TResult>>

A function that returns a started task of type TResult.

verifySucceeded
Func<DbContext,TState,CancellationToken,Task<ExecutionResult<TResult>>>

A delegate that tests whether the operation succeeded even though an exception was thrown.

cancellationToken
CancellationToken

A cancellation token used to cancel the retry operation, but not operations that are already in flight or that already completed successfully.

Returns

Task<TResult>

A task that will run to completion if the original task completes successfully (either the first time or after retrying transient failures). If the task fails with a non-transient error or the retry limit is reached, the returned task will become faulted and the exception must be observed.

Implements

Exceptions

The operation has not succeeded after the configured number of retries.

Remarks

See Connection resiliency and database retries for more information and examples.

Applies to

ExecuteAsync<TState,TResult>(Func<TState,CancellationToken,Task<TResult>>, Func<TState,CancellationToken,Task<ExecutionResult<TResult>>>, TState, CancellationToken)

Executes the specified asynchronous operation and returns the result.

public virtual System.Threading.Tasks.Task<TResult> ExecuteAsync<TState,TResult> (Func<TState,System.Threading.CancellationToken,System.Threading.Tasks.Task<TResult>> operation, Func<TState,System.Threading.CancellationToken,System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.Storage.ExecutionResult<TResult>>> verifySucceeded, TState state, System.Threading.CancellationToken cancellationToken = default);
abstract member ExecuteAsync : Func<'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<'Result>> * Func<'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.Storage.ExecutionResult<'Result>>> * 'State * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
override this.ExecuteAsync : Func<'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<'Result>> * Func<'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.Storage.ExecutionResult<'Result>>> * 'State * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
Public Overridable Function ExecuteAsync(Of TState, TResult) (operation As Func(Of TState, CancellationToken, Task(Of TResult)), verifySucceeded As Func(Of TState, CancellationToken, Task(Of ExecutionResult(Of TResult))), state As TState, Optional cancellationToken As CancellationToken = Nothing) As Task(Of TResult)

Type Parameters

TState

The type of the state.

TResult

The result type of the Task<TResult> returned by operation.

Parameters

operation
Func<TState,CancellationToken,Task<TResult>>

A function that returns a started task of type TResult.

verifySucceeded
Func<TState,CancellationToken,Task<ExecutionResult<TResult>>>

A delegate that tests whether the operation succeeded even though an exception was thrown.

state
TState

The state that will be passed to the operation.

cancellationToken
CancellationToken

A cancellation token used to cancel the retry operation, but not operations that are already in flight or that already completed successfully.

Returns

Task<TResult>

A task that will run to completion if the original task completes successfully (either the first time or after retrying transient failures). If the task fails with a non-transient error or the retry limit is reached, the returned task will become faulted and the exception must be observed.

Implements

Exceptions

Thrown if the operation has not succeeded after the configured number of retries.

Applies to