Table of Contents

Class RetrySyntaxAsync

Namespace
Polly
Assembly
Polly.dll

Fluent API for defining a Retry Policy.

public static class RetrySyntaxAsync
Inheritance
RetrySyntaxAsync
Inherited Members

Methods

RetryAsync(PolicyBuilder)

Builds a Policy that will retry once.

public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder)

Parameters

policyBuilder PolicyBuilder

The policy builder.

Returns

RetryPolicy

The policy instance.

RetryAsync(PolicyBuilder, Action<Exception, int, Context>)

Builds a Policy that will retry once calling onRetry on retry with the raised exception, retry count and context data.

public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Action<Exception, int, Context> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

onRetry Action<Exception, int, Context>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

onRetry

RetryAsync(PolicyBuilder, Action<Exception, int>)

Builds a Policy that will retry once calling onRetry on retry with the raised exception and retry count.

public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Action<Exception, int> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

onRetry Action<Exception, int>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

onRetry

RetryAsync(PolicyBuilder, Func<Exception, int, Context, Task>)

Builds a Policy that will retry once calling onRetryAsync on retry with the raised exception, retry count and context data.

public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Func<Exception, int, Context, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

onRetryAsync Func<Exception, int, Context, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

onRetry

RetryAsync(PolicyBuilder, Func<Exception, int, Task>)

Builds a Policy that will retry once calling onRetryAsync on retry with the raised exception and retry count.

public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Func<Exception, int, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

onRetryAsync Func<Exception, int, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

onRetry

RetryAsync(PolicyBuilder, int)

Builds a Policy that will retry retryCount times.

public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

Returns

RetryPolicy

The policy instance.

RetryAsync(PolicyBuilder, int, Action<Exception, int, Context>)

Builds a Policy that will retry retryCount times calling onRetry on each retry with the raised exception, retry count and context data.

public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount, Action<Exception, int, Context> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

onRetry Action<Exception, int, Context>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentOutOfRangeException

retryCount;Value must be greater than zero.

ArgumentNullException

onRetry

RetryAsync(PolicyBuilder, int, Action<Exception, int>)

Builds a Policy that will retry retryCount times calling onRetry on each retry with the raised exception and retry count.

public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount, Action<Exception, int> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

onRetry Action<Exception, int>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentOutOfRangeException

retryCount;Value must be greater than or equal to zero.

ArgumentNullException

onRetry

RetryAsync(PolicyBuilder, int, Func<Exception, int, Context, Task>)

Builds a Policy that will retry retryCount times calling onRetryAsync on each retry with the raised exception, retry count and context data.

public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<Exception, int, Context, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

onRetryAsync Func<Exception, int, Context, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentOutOfRangeException

retryCount;Value must be greater than zero.

ArgumentNullException

onRetryAsync

RetryAsync(PolicyBuilder, int, Func<Exception, int, Task>)

Builds a Policy that will retry retryCount times calling onRetryAsync on each retry with the raised exception and retry count.

public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<Exception, int, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

onRetryAsync Func<Exception, int, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentOutOfRangeException

retryCount;Value must be greater than or equal to zero.

ArgumentNullException

onRetryAsync

RetryForeverAsync(PolicyBuilder)

Builds a Policy that will retry indefinitely until the action succeeds.

public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder)

Parameters

policyBuilder PolicyBuilder

The policy builder.

Returns

RetryPolicy

The policy instance.

RetryForeverAsync(PolicyBuilder, Action<Exception, Context>)

Builds a Policy that will retry indefinitely calling onRetry on each retry with the raised exception and context data.

public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Action<Exception, Context> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

onRetry Action<Exception, Context>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

onRetry

RetryForeverAsync(PolicyBuilder, Action<Exception>)

Builds a Policy that will retry indefinitely calling onRetry on each retry with the raised exception.

public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Action<Exception> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

onRetry Action<Exception>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

onRetry

RetryForeverAsync(PolicyBuilder, Func<Exception, Context, Task>)

Builds a Policy that will retry indefinitely calling onRetryAsync on each retry with the raised exception and context data.

public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Func<Exception, Context, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

onRetryAsync Func<Exception, Context, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

onRetryAsync

RetryForeverAsync(PolicyBuilder, Func<Exception, Task>)

Builds a Policy that will retry indefinitely calling onRetryAsync on each retry with the raised exception.

public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Func<Exception, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

onRetryAsync Func<Exception, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

onRetryAsync

WaitAndRetryAsync(PolicyBuilder, IEnumerable<TimeSpan>)

Builds a Policy that will wait and retry as many times as there are provided sleepDurations On each retry, the duration to wait is the current sleepDurations item.

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations)

Parameters

policyBuilder PolicyBuilder

The policy builder.

sleepDurations IEnumerable<TimeSpan>

The sleep durations to wait for on each retry.

Returns

RetryPolicy

The policy instance.

WaitAndRetryAsync(PolicyBuilder, IEnumerable<TimeSpan>, Action<Exception, TimeSpan, Context>)

Builds a Policy that will wait and retry as many times as there are provided sleepDurations calling onRetry on each retry with the raised exception, the current sleep duration and context data. On each retry, the duration to wait is the current sleepDurations item.

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Action<Exception, TimeSpan, Context> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

sleepDurations IEnumerable<TimeSpan>

The sleep durations to wait for on each retry.

onRetry Action<Exception, TimeSpan, Context>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

sleepDurations or onRetry

WaitAndRetryAsync(PolicyBuilder, IEnumerable<TimeSpan>, Action<Exception, TimeSpan, int, Context>)

Builds a Policy that will wait and retry as many times as there are provided sleepDurations calling onRetry on each retry with the raised exception, the current sleep duration, retry count, and context data. On each retry, the duration to wait is the current sleepDurations item.

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Action<Exception, TimeSpan, int, Context> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

sleepDurations IEnumerable<TimeSpan>

The sleep durations to wait for on each retry.

onRetry Action<Exception, TimeSpan, int, Context>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

sleepDurations or onRetry

WaitAndRetryAsync(PolicyBuilder, IEnumerable<TimeSpan>, Action<Exception, TimeSpan>)

Builds a Policy that will wait and retry as many times as there are provided sleepDurations calling onRetry on each retry with the raised exception and the current sleep duration. On each retry, the duration to wait is the current sleepDurations item.

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Action<Exception, TimeSpan> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

sleepDurations IEnumerable<TimeSpan>

The sleep durations to wait for on each retry.

onRetry Action<Exception, TimeSpan>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

sleepDurations or onRetry

WaitAndRetryAsync(PolicyBuilder, IEnumerable<TimeSpan>, Func<Exception, TimeSpan, Context, Task>)

Builds a Policy that will wait and retry as many times as there are provided sleepDurations calling onRetryAsync on each retry with the raised exception, the current sleep duration and context data. On each retry, the duration to wait is the current sleepDurations item.

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Func<Exception, TimeSpan, Context, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

sleepDurations IEnumerable<TimeSpan>

The sleep durations to wait for on each retry.

onRetryAsync Func<Exception, TimeSpan, Context, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

sleepDurations or onRetryAsync

WaitAndRetryAsync(PolicyBuilder, IEnumerable<TimeSpan>, Func<Exception, TimeSpan, int, Context, Task>)

Builds a Policy that will wait and retry as many times as there are provided sleepDurations calling onRetryAsync on each retry with the raised exception, the current sleep duration, retry count, and context data. On each retry, the duration to wait is the current sleepDurations item.

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Func<Exception, TimeSpan, int, Context, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

sleepDurations IEnumerable<TimeSpan>

The sleep durations to wait for on each retry.

onRetryAsync Func<Exception, TimeSpan, int, Context, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

sleepDurations or onRetryAsync

WaitAndRetryAsync(PolicyBuilder, IEnumerable<TimeSpan>, Func<Exception, TimeSpan, Task>)

Builds a Policy that will wait and retry as many times as there are provided sleepDurations calling onRetryAsync on each retry with the raised exception and the current sleep duration. On each retry, the duration to wait is the current sleepDurations item.

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Func<Exception, TimeSpan, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

sleepDurations IEnumerable<TimeSpan>

The sleep durations to wait for on each retry.

onRetryAsync Func<Exception, TimeSpan, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

sleepDurations or onRetryAsync

WaitAndRetryAsync(PolicyBuilder, int, Func<int, Context, TimeSpan>, Action<Exception, TimeSpan, Context>)

Builds a Policy that will wait and retry retryCount times calling onRetry on each retry with the raised exception, the current sleep duration and context data. On each retry, the duration to wait is calculated by calling sleepDurationProvider with the current retry attempt allowing an exponentially increasing wait time (exponential backoff).

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, Context, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, Context> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

sleepDurationProvider Func<int, Context, TimeSpan>

The function that provides the duration to wait for for a particular retry attempt.

onRetry Action<Exception, TimeSpan, Context>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentOutOfRangeException

retryCount;Value must be greater than or equal to zero.

ArgumentNullException

sleepDurationProvider or onRetry

WaitAndRetryAsync(PolicyBuilder, int, Func<int, Context, TimeSpan>, Action<Exception, TimeSpan, int, Context>)

Builds a Policy that will wait and retry retryCount times calling onRetry on each retry with the raised exception, the current sleep duration, retry count, and context data. On each retry, the duration to wait is calculated by calling sleepDurationProvider with the current retry attempt allowing an exponentially increasing wait time (exponential backoff).

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, Context, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, int, Context> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

sleepDurationProvider Func<int, Context, TimeSpan>

The function that provides the duration to wait for for a particular retry attempt.

onRetry Action<Exception, TimeSpan, int, Context>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentOutOfRangeException

retryCount;Value must be greater than or equal to zero.

ArgumentNullException

sleepDurationProvider or onRetry

WaitAndRetryAsync(PolicyBuilder, int, Func<int, Context, TimeSpan>, Func<Exception, TimeSpan, Context, Task>)

Builds a Policy that will wait and retry retryCount times calling onRetryAsync on each retry with the raised exception, the current sleep duration and context data. On each retry, the duration to wait is calculated by calling sleepDurationProvider with the current retry attempt allowing an exponentially increasing wait time (exponential backoff).

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, Context, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, Context, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

sleepDurationProvider Func<int, Context, TimeSpan>

The function that provides the duration to wait for for a particular retry attempt.

onRetryAsync Func<Exception, TimeSpan, Context, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentOutOfRangeException

retryCount;Value must be greater than or equal to zero.

ArgumentNullException

sleepDurationProvider or onRetryAsync

WaitAndRetryAsync(PolicyBuilder, int, Func<int, Context, TimeSpan>, Func<Exception, TimeSpan, int, Context, Task>)

Builds a Policy that will wait and retry retryCount times calling onRetryAsync on each retry with the raised exception, the current sleep duration, retry count, and context data. On each retry, the duration to wait is calculated by calling sleepDurationProvider with the current retry attempt allowing an exponentially increasing wait time (exponential backoff).

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, Context, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, int, Context, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

sleepDurationProvider Func<int, Context, TimeSpan>

The function that provides the duration to wait for for a particular retry attempt.

onRetryAsync Func<Exception, TimeSpan, int, Context, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentOutOfRangeException

retryCount;Value must be greater than or equal to zero.

ArgumentNullException

sleepDurationProvider or onRetryAsync

WaitAndRetryAsync(PolicyBuilder, int, Func<int, TimeSpan>)

Builds a Policy that will wait and retry retryCount times. On each retry, the duration to wait is calculated by calling sleepDurationProvider with the current retry attempt allowing an exponentially increasing wait time (exponential backoff).

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

sleepDurationProvider Func<int, TimeSpan>

The function that provides the duration to wait for for a particular retry attempt.

Returns

RetryPolicy

The policy instance.

WaitAndRetryAsync(PolicyBuilder, int, Func<int, TimeSpan>, Action<Exception, TimeSpan, Context>)

Builds a Policy that will wait and retry retryCount times calling onRetry on each retry with the raised exception, the current sleep duration and context data. On each retry, the duration to wait is calculated by calling sleepDurationProvider with the current retry attempt allowing an exponentially increasing wait time (exponential backoff).

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, Context> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

sleepDurationProvider Func<int, TimeSpan>

The function that provides the duration to wait for for a particular retry attempt.

onRetry Action<Exception, TimeSpan, Context>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentOutOfRangeException

retryCount;Value must be greater than or equal to zero.

ArgumentNullException

sleepDurationProvider or onRetry

WaitAndRetryAsync(PolicyBuilder, int, Func<int, TimeSpan>, Action<Exception, TimeSpan, int, Context>)

Builds a Policy that will wait and retry retryCount times calling onRetry on each retry with the raised exception, the current sleep duration, retry count, and context data. On each retry, the duration to wait is calculated by calling sleepDurationProvider with the current retry attempt allowing an exponentially increasing wait time (exponential backoff).

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, int, Context> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

sleepDurationProvider Func<int, TimeSpan>

The function that provides the duration to wait for for a particular retry attempt.

onRetry Action<Exception, TimeSpan, int, Context>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentOutOfRangeException

retryCount;Value must be greater than or equal to zero.

ArgumentNullException

sleepDurationProvider or onRetry

WaitAndRetryAsync(PolicyBuilder, int, Func<int, TimeSpan>, Action<Exception, TimeSpan>)

Builds a Policy that will wait and retry retryCount times calling onRetry on each retry with the raised exception and the current sleep duration. On each retry, the duration to wait is calculated by calling sleepDurationProvider with the current retry attempt allowing an exponentially increasing wait time (exponential backoff).

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

sleepDurationProvider Func<int, TimeSpan>

The function that provides the duration to wait for for a particular retry attempt.

onRetry Action<Exception, TimeSpan>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentOutOfRangeException

retryCount;Value must be greater than or equal to zero.

ArgumentNullException

sleepDurationProvider or onRetry

WaitAndRetryAsync(PolicyBuilder, int, Func<int, TimeSpan>, Func<Exception, TimeSpan, Context, Task>)

Builds a Policy that will wait and retry retryCount times calling onRetryAsync on each retry with the raised exception, the current sleep duration and context data. On each retry, the duration to wait is calculated by calling sleepDurationProvider with the current retry attempt allowing an exponentially increasing wait time (exponential backoff).

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, Context, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

sleepDurationProvider Func<int, TimeSpan>

The function that provides the duration to wait for for a particular retry attempt.

onRetryAsync Func<Exception, TimeSpan, Context, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentOutOfRangeException

retryCount;Value must be greater than or equal to zero.

ArgumentNullException

sleepDurationProvider or onRetryAsync

WaitAndRetryAsync(PolicyBuilder, int, Func<int, TimeSpan>, Func<Exception, TimeSpan, int, Context, Task>)

Builds a Policy that will wait and retry retryCount times calling onRetryAsync on each retry with the raised exception, the current sleep duration, retry count, and context data. On each retry, the duration to wait is calculated by calling sleepDurationProvider with the current retry attempt allowing an exponentially increasing wait time (exponential backoff).

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, int, Context, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

sleepDurationProvider Func<int, TimeSpan>

The function that provides the duration to wait for for a particular retry attempt.

onRetryAsync Func<Exception, TimeSpan, int, Context, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentOutOfRangeException

retryCount;Value must be greater than or equal to zero.

ArgumentNullException

sleepDurationProvider or onRetryAsync

WaitAndRetryAsync(PolicyBuilder, int, Func<int, TimeSpan>, Func<Exception, TimeSpan, Task>)

Builds a Policy that will wait and retry retryCount times calling onRetryAsync on each retry with the raised exception and the current sleep duration. On each retry, the duration to wait is calculated by calling sleepDurationProvider with the current retry attempt allowing an exponentially increasing wait time (exponential backoff).

public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

retryCount int

The retry count.

sleepDurationProvider Func<int, TimeSpan>

The function that provides the duration to wait for for a particular retry attempt.

onRetryAsync Func<Exception, TimeSpan, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentOutOfRangeException

retryCount;Value must be greater than or equal to zero.

ArgumentNullException

sleepDurationProvider or onRetryAsync

WaitAndRetryForeverAsync(PolicyBuilder, Func<int, Context, TimeSpan>)

Builds a Policy that will wait and retry indefinitely until the action succeeds.

public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, Context, TimeSpan> sleepDurationProvider)

Parameters

policyBuilder PolicyBuilder

The policy builder.

sleepDurationProvider Func<int, Context, TimeSpan>

The function that provides the duration to wait for for a particular retry attempt.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

sleepDurationProvider

WaitAndRetryForeverAsync(PolicyBuilder, Func<int, Context, TimeSpan>, Action<Exception, TimeSpan, Context>)

Builds a Policy that will wait and retry indefinitely calling onRetry on each retry with the raised exception and execution context.

public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, Context, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, Context> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

sleepDurationProvider Func<int, Context, TimeSpan>

A function providing the duration to wait before retrying.

onRetry Action<Exception, TimeSpan, Context>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

sleepDurationProvider

ArgumentNullException

onRetry

WaitAndRetryForeverAsync(PolicyBuilder, Func<int, Context, TimeSpan>, Func<Exception, TimeSpan, Context, Task>)

Builds a Policy that will wait and retry indefinitely calling onRetryAsync on each retry with the raised exception and execution context.

public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, Context, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, Context, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

sleepDurationProvider Func<int, Context, TimeSpan>

A function providing the duration to wait before retrying.

onRetryAsync Func<Exception, TimeSpan, Context, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

sleepDurationProvider

ArgumentNullException

onRetryAsync

WaitAndRetryForeverAsync(PolicyBuilder, Func<int, TimeSpan>)

Builds a Policy that will wait and retry indefinitely until the action succeeds.

public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, TimeSpan> sleepDurationProvider)

Parameters

policyBuilder PolicyBuilder

The policy builder.

sleepDurationProvider Func<int, TimeSpan>

The function that provides the duration to wait for for a particular retry attempt.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

sleepDurationProvider

WaitAndRetryForeverAsync(PolicyBuilder, Func<int, TimeSpan>, Action<Exception, TimeSpan>)

Builds a Policy that will wait and retry indefinitely calling onRetry on each retry with the raised exception.

public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan> onRetry)

Parameters

policyBuilder PolicyBuilder

The policy builder.

sleepDurationProvider Func<int, TimeSpan>

A function providing the duration to wait before retrying.

onRetry Action<Exception, TimeSpan>

The action to call on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

sleepDurationProvider

ArgumentNullException

onRetry

WaitAndRetryForeverAsync(PolicyBuilder, Func<int, TimeSpan>, Func<Exception, TimeSpan, Task>)

Builds a Policy that will wait and retry indefinitely calling onRetryAsync on each retry with the raised exception.

public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, Task> onRetryAsync)

Parameters

policyBuilder PolicyBuilder

The policy builder.

sleepDurationProvider Func<int, TimeSpan>

A function providing the duration to wait before retrying.

onRetryAsync Func<Exception, TimeSpan, Task>

The action to call asynchronously on each retry.

Returns

RetryPolicy

The policy instance.

Exceptions

ArgumentNullException

sleepDurationProvider

ArgumentNullException

onRetryAsync