# AsyncExecutorWithRetries Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.internal.asyncexecutorwithretries/)

## ExecuteWithRetries(Func&lt;int, Task&gt;, int, Func&lt;Exception, int, bool&gt;, TimeSpan, IBackoffProvider) {#executewithretries-system-func-int-system-threading-tasks-task-int-system-func-s-f16ad60e}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.internal.asyncexecutorwithretries/methods/executewithretries-system-func-int-system-threading-tasks-task-int-system-func-s-f16ad60e/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Async/AsyncExecutorWithRetries.cs#L50-L59)

```csharp
public static Task ExecuteWithRetries(Func<int, Task> action, int maxNumErrorTries, Func<Exception, int, bool> retryExceptionFilter, TimeSpan maxExecutionTime, IBackoffProvider onErrorBackOff)
```

Execute a given function a number of times, based on retry configuration parameters.

### Parameters

- `action` (`Func<int, Task>`): The action to be executed.
- `maxNumErrorTries` (`int`): The maximum number of retries.
- `retryExceptionFilter` (`Func<Exception, int, bool>`): The retry exception filter.
- `maxExecutionTime` (`TimeSpan`): The maximum execution time.
- `onErrorBackOff` (`IBackoffProvider`): The backoff provider.

### Returns

A `System.Threading.Tasks.Task` representing the operation.

## ExecuteWithRetries(Func&lt;int, Task&lt;T&gt;&gt;, int, Func&lt;Exception, int, bool&gt;, TimeSpan, IBackoffProvider, CancellationToken) {#executewithretries-1-system-func-int-system-threading-tasks-task-t-int-system-fu-ec2eb6c3}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.internal.asyncexecutorwithretries/methods/executewithretries-1-system-func-int-system-threading-tasks-task-t-int-system-fu-ec2eb6c3/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Async/AsyncExecutorWithRetries.cs#L91-L100)

```csharp
public static Task<T> ExecuteWithRetries<T>(Func<int, Task<T>> function, int maxNumErrorTries, Func<Exception, int, bool> retryExceptionFilter, TimeSpan maxExecutionTime, IBackoffProvider onErrorBackOff, CancellationToken cancellationToken = default(CancellationToken))
```

Execute a given function a number of times, based on retry configuration parameters.

### Parameters

- `function` (`Func<int, Task<T>>`): The delegate to be executed.
- `maxNumErrorTries` (`int`): The maximum number of retries.
- `retryExceptionFilter` (`Func<Exception, int, bool>`): The retry exception filter.
- `maxExecutionTime` (`TimeSpan`): The maximum execution time.
- `onErrorBackOff` (`IBackoffProvider`): The backoff provider.
- `cancellationToken` (`CancellationToken`)

### Returns

The value returned from the successful invocation of the provided function.

## ExecuteWithRetries(Func&lt;int, Task&lt;T&gt;&gt;, int, int, Func&lt;T, int, bool&gt;, Func&lt;Exception, int, bool&gt;, TimeSpan, IBackoffProvider, IBackoffProvider, CancellationToken) {#executewithretries-1-system-func-int-system-threading-tasks-task-t-int-int-syste-47060420}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.internal.asyncexecutorwithretries/methods/executewithretries-1-system-func-int-system-threading-tasks-task-t-int-int-syste-47060420/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core/Async/AsyncExecutorWithRetries.cs#L149-L159)

```csharp
public static Task<T> ExecuteWithRetries<T>(Func<int, Task<T>> function, int maxNumSuccessTries, int maxNumErrorTries, Func<T, int, bool> retryValueFilter, Func<Exception, int, bool> retryExceptionFilter, TimeSpan maxExecutionTime = default(TimeSpan), IBackoffProvider onSuccessBackOff = null, IBackoffProvider onErrorBackOff = null, CancellationToken cancellationToken = default(CancellationToken))
```

Execute a given `function` a number of times, based on retry configuration parameters.

### Parameters

- `function` (`Func<int, Task<T>>`): Function to execute
- `maxNumSuccessTries` (`int`): Maximal number of successful execution attempts. [AsyncExecutorWithRetries](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.internal.asyncexecutorwithretries/) will try to re-execute the given `function` again if directed so by `retryValueFilter` . Set to `-1` for unlimited number of success retries, until `retryValueFilter` is satisfied. Set to `0` for only one success attempt, which will cause `retryValueFilter` to be ignored and the given `function` executed only once until first success.
- `maxNumErrorTries` (`int`): Maximal number of execution attempts due to errors. Set to -1 for unlimited number of error retries, until `retryExceptionFilter` is satisfied.
- `retryValueFilter` (`Func<T, int, bool>`): Filter `function` to indicate if successful execution should be retried. Set to `null` to disable successful retries.
- `retryExceptionFilter` (`Func<Exception, int, bool>`): Filter `function` to indicate if error execution should be retried. Set to `null` to disable error retries.
- `maxExecutionTime` (`TimeSpan`): The maximal execution time of the [AsyncExecutorWithRetries](/orleans/docs/api/csharp/microsoft.orleans.core/orleans.internal.asyncexecutorwithretries/) function.
- `onSuccessBackOff` (`IBackoffProvider`): The backoff provider object, which determines how much to wait between success retries.
- `onErrorBackOff` (`IBackoffProvider`): The backoff provider object, which determines how much to wait between error retries
- `cancellationToken` (`CancellationToken`)

### Returns

The value returned from the successful invocation of `function`.
