Show / Hide Table of Contents

Class ExecutionStrategy

The base class for IExecutionStrategy implementations.

Inheritance
Object
SuspendableExecutionStrategy
ExecutionStrategy
Inherited Members
SuspendableExecutionStrategy.Suspended
SuspendableExecutionStrategy.RetriesOnFailure
System.Object.ToString()
Object.Equals(Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
Object.MemberwiseClone()
Namespace: IRM.TransientFaultHandling
Assembly: IRM.dll
Syntax
public abstract class ExecutionStrategy : SuspendableExecutionStrategy, IExecutionStrategy

Constructors

ExecutionStrategy(Int32, TimeSpan)

Creates a new instance of ExecutionStrategy.

Declaration
protected ExecutionStrategy(int maxRetryCount, TimeSpan maxRetryDelay)
Parameters
System.Int32 maxRetryCount

The maximum number of retry attempts.

TimeSpan maxRetryDelay

The maximum delay between retries.

Fields

DefaultMaxDelay

The default maximum time delay between retries, must be nonnegative.

Declaration
protected static readonly TimeSpan DefaultMaxDelay
Field Value
TimeSpan

DefaultMaxRetryCount

The default number of retry attempts.

Declaration
protected static readonly int DefaultMaxRetryCount
Field Value
System.Int32

Properties

ExceptionsEncountered

The list of exceptions that caused the operation to be retried so far.

Declaration
protected virtual List<Exception> ExceptionsEncountered { get; }
Property Value
List<Exception>

MaxRetryCount

The maximum number of retry attempts.

Declaration
protected virtual int MaxRetryCount { get; }
Property Value
System.Int32

MaxRetryDelay

The maximum delay between retries.

Declaration
protected virtual TimeSpan MaxRetryDelay { get; }
Property Value
TimeSpan

Random

A pseudo-random number generator that can be used to vary the delay between retries.

Declaration
protected virtual Random Random { get; }
Property Value
Random

Methods

Execute<TResult>(Func<TResult>)

Executes the specified operation and returns the result.

Declaration
public override TResult Execute<TResult>(Func<TResult> operation)
Parameters
System.Func<TResult> operation

A delegate representing an executable operation that returns the result of type TResult.

Returns
TResult

The result from the operation.

Type Parameters
TResult

The return type of operation.

Overrides
IRM.TransientFaultHandling.SuspendableExecutionStrategy.Execute<TResult>(System.Func<TResult>)
Implements
IExecutionStrategy.Execute<TResult>(Func<TResult>)
Exceptions
RetryLimitExceededException

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

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

Executes the specified asynchronous operation and returns the result.

Declaration
public override Task<TResult> ExecuteAsync<TResult>(Func<CancellationToken, Task<TResult>> operation, CancellationToken cancellationToken = default(CancellationToken))
Parameters
System.Func<System.Threading.CancellationToken, System.Threading.Tasks.Task<TResult>> operation

A function that returns a started task of type TResult.

System.Threading.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
System.Threading.Tasks.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.

Type Parameters
TResult

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

Overrides
IRM.TransientFaultHandling.SuspendableExecutionStrategy.ExecuteAsync<TResult>(System.Func<System.Threading.CancellationToken, System.Threading.Tasks.Task<TResult>>, System.Threading.CancellationToken)
Implements
IExecutionStrategy.ExecuteAsync<TResult>(Func<CancellationToken, Task<TResult>>, CancellationToken)
Exceptions
RetryLimitExceededException

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

GetNextDelay(Exception)

Determines whether the operation should be retried and the delay before the next attempt.

Declaration
protected virtual TimeSpan? GetNextDelay(Exception lastException)
Parameters
Exception lastException

The exception thrown during the last execution attempt.

Returns
System.Nullable<TimeSpan>

Returns the delay indicating how long to wait for before the next execution attempt if the operation should be retried; null otherwise

OnFirstExecution()

Method called before the first operation execution

Declaration
protected virtual void OnFirstExecution()

OnRetry()

Method called before retrying the operation execution

Declaration
protected virtual void OnRetry()

ShouldRetryOn(Exception)

Determines whether the specified exception represents a transient failure that can be compensated by a retry.

Declaration
protected abstract bool ShouldRetryOn(Exception exception)
Parameters
Exception exception

The exception object to be verified.

Returns
Boolean

true if the specified exception is considered as transient, otherwise false.

ShouldVerifySuccessOn(Exception)

Determines whether the specified exception could be thrown after a successful execution.

Declaration
protected virtual bool ShouldVerifySuccessOn(Exception exception)
Parameters
Exception exception

The exception object to be verified.

Returns
Boolean

true if the specified exception could be thrown after a successful execution, otherwise false.

Extension Methods

ObjectExtensions.DeepClone<T>(T)
ExecutionStrategyExtensions.Execute(IExecutionStrategy, Action)
ExecutionStrategyExtensions.ExecuteAsync(IExecutionStrategy, Func<Task>)
ExecutionStrategyExtensions.ExecuteAsync(IExecutionStrategy, Func<CancellationToken, Task>, CancellationToken)
AnnotationsExtensions.IsValid(Object)
Back to top Generated by DocFX