# Class RetrySettings (4.10.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [4.10.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings)
- [4.8.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.8.0/Google.Api.Gax.Grpc.RetrySettings)
- [4.4.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.4.0/Google.Api.Gax.Grpc.RetrySettings)
- [4.3.1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.3.1/Google.Api.Gax.Grpc.RetrySettings)
- [4.2.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.2.0/Google.Api.Gax.Grpc.RetrySettings)
- [4.0.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.0.0/Google.Api.Gax.Grpc.RetrySettings)
- [3.2.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/3.2.0/Google.Api.Gax.Grpc.RetrySettings)

    public sealed class RetrySettings

Settings for retrying RPCs.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> RetrySettings

## Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Api.Gax.Grpc](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc)

## Assembly

Google.Api.Gax.Grpc.dll

## Properties

### BackoffJitter

    public RetrySettings.IJitter BackoffJitter { get; }

The delay jitter to apply for delays, defaulting to [RandomJitter](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings#Google_Api_Gax_Grpc_RetrySettings_RandomJitter). This is never null.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettingshttps://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings.IJitter` |   |

**Remarks** "Jitter" is used to introduce randomness into the pattern of delays. This is to avoid multiple
clients performing the same delay pattern starting at the same point in time,
leading to higher-than-necessary contention. The default jitter simply takes each maximum delay
and returns an actual delay which is a uniformly random value between 0 and the maximum. This
is good enough for most applications, but makes precise testing difficult.

### BackoffMultiplier

    public double BackoffMultiplier { get; }

The multiplier to apply to the backoff on each iteration; always greater than or equal to 1.0.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.double` |   |

**Remarks**
As an example, a multiplier of 2.0 with an initial backoff of 0.1s on an RPC would then apply
a backoff of 0.2s, then 0.4s until it is capped by [MaxBackoff](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings#Google_Api_Gax_Grpc_RetrySettings_MaxBackoff).

### InitialBackoff

    public TimeSpan InitialBackoff { get; }

The backoff time between the first attempt and the first retry. Always non-negative.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` |   |

### MaxAttempts

    public int MaxAttempts { get; }

The maximum number of attempts to make. Always greater than or equal to 1.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.int32` |   |

### MaxBackoff

    public TimeSpan MaxBackoff { get; }

The maximum backoff time between retries. Always non-negative.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` |   |

### NoJitter

    public static RetrySettings.IJitter NoJitter { get; }

A jitter which simply returns the specified maximum delay.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettingshttps://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings.IJitter` |   |

### RandomJitter

    public static RetrySettings.IJitter RandomJitter { get; }

The default jitter which returns a uniformly distributed random delay between 0 and
the specified maximum.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettingshttps://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings.IJitter` |   |

### RetryFilter

    public Predicate<Exception> RetryFilter { get; }

A predicate to determine whether or not a particular exception should cause the operation to be retried.
Usually this is simply a matter of checking the status codes. This is never null.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.predicate-1https://learn.microsoft.com/dotnet/api/system.exception` |   |

## Methods

### FilterForStatusCodes(params StatusCode\[\])

    public static Predicate<Exception> FilterForStatusCodes(params StatusCode[] statusCodes)

Creates a retry filter based on status codes.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `statusCodes` | `https://github.com/grpc/grpc-dotnet/blob/7c43ddb5d68008782dc0dba2d0feaa3ed91a9fb2/src/Grpc.Core.Api/StatusCode.cs` The status codes to retry. Must not be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.predicate-1https://learn.microsoft.com/dotnet/api/system.exception` | A retry filter based on status codes. |

### FilterForStatusCodes(IEnumerable\<StatusCode\>)

    public static Predicate<Exception> FilterForStatusCodes(IEnumerable<StatusCode> statusCodes)

Creates a retry filter based on status codes.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `statusCodes` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://github.com/grpc/grpc-dotnet/blob/7c43ddb5d68008782dc0dba2d0feaa3ed91a9fb2/src/Grpc.Core.Api/StatusCode.cs` The status codes to retry. Must not be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.predicate-1https://learn.microsoft.com/dotnet/api/system.exception` | A retry filter based on status codes. |

### FromConstantBackoff(int, TimeSpan, Predicate\<Exception\>, IJitter)

    public static RetrySettings FromConstantBackoff(int maxAttempts, TimeSpan backoff, Predicate<Exception> retryFilter, RetrySettings.IJitter backoffJitter = null)

Returns a [RetrySettings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings) using the specified maximum number of attempts and a constant backoff.
Jitter is still applied to each backoff, but the "base" value of the backoff is always `backoff`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `maxAttempts` | `https://learn.microsoft.com/dotnet/api/system.int32` The maximum number of attempts to make. Must be positive. |
| `backoff` | `https://learn.microsoft.com/dotnet/api/system.timespan` The backoff after each failure. Must be non-negative. |
| `retryFilter` | `https://learn.microsoft.com/dotnet/api/system.predicate-1https://learn.microsoft.com/dotnet/api/system.exception` The predicate to use to check whether an error should be retried. Must not be null. |
| `backoffJitter` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettingshttps://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings.IJitter` The jitter to use on each backoff. May be null, in which case [RandomJitter](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings#Google_Api_Gax_Grpc_RetrySettings_RandomJitter) is used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings` | A retry with constant backoff. |

### FromExponentialBackoff(int, TimeSpan, TimeSpan, double, Predicate\<Exception\>, IJitter)

    public static RetrySettings FromExponentialBackoff(int maxAttempts, TimeSpan initialBackoff, TimeSpan maxBackoff, double backoffMultiplier, Predicate<Exception> retryFilter, RetrySettings.IJitter backoffJitter = null)

Returns a [RetrySettings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings) using the specified maximum number of attempts and an exponential backoff.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `maxAttempts` | `https://learn.microsoft.com/dotnet/api/system.int32` The maximum number of attempts to make. Must be positive. |
| `initialBackoff` | `https://learn.microsoft.com/dotnet/api/system.timespan` The backoff after the initial failure. Must be non-negative. |
| `maxBackoff` | `https://learn.microsoft.com/dotnet/api/system.timespan` The maximum backoff. Must be at least `initialBackoff`. |
| `backoffMultiplier` | `https://learn.microsoft.com/dotnet/api/system.double` The multiplier to apply to backoff times. Must be at least 1.0. |
| `retryFilter` | `https://learn.microsoft.com/dotnet/api/system.predicate-1https://learn.microsoft.com/dotnet/api/system.exception` The predicate to use to check whether an error should be retried. Must not be null. |
| `backoffJitter` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettingshttps://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings.IJitter` The jitter to use on each backoff. May be null, in which case [RandomJitter](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings#Google_Api_Gax_Grpc_RetrySettings_RandomJitter) is used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings` | A retry with exponential backoff. |

### NextBackoff(TimeSpan)

    public TimeSpan NextBackoff(TimeSpan currentBackoff)

Works out the next backoff from the current one, based on the multiplier and maximum.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `currentBackoff` | `https://learn.microsoft.com/dotnet/api/system.timespan` The current backoff to use as a basis for the next one. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` | The next backoff to use, which is always at least [InitialBackoff](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings#Google_Api_Gax_Grpc_RetrySettings_InitialBackoff) and at most [MaxBackoff](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RetrySettings#Google_Api_Gax_Grpc_RetrySettings_MaxBackoff). |