Table of Contents

Class RetryDelegatingHandler

Namespace
MADE.Networking.Http
Assembly
MADE.Networking.dll

Defines a delegating handler that retries failed HTTP requests with exponential backoff.

public class RetryDelegatingHandler : DelegatingHandler, IDisposable
Inheritance
RetryDelegatingHandler
Implements
Inherited Members
Extension Methods

Remarks

Use this handler when constructing an HttpClient to automatically retry transient failures.

var handler = new RetryDelegatingHandler(maxRetries: 3, initialDelay: TimeSpan.FromSeconds(1));
var client = new HttpClient(handler);

Constructors

RetryDelegatingHandler(int, TimeSpan?)

Initializes a new instance of the RetryDelegatingHandler class.

public RetryDelegatingHandler(int maxRetries = 3, TimeSpan? initialDelay = null)

Parameters

maxRetries int

The maximum number of retry attempts. Default is 3.

initialDelay TimeSpan?

The initial delay before the first retry. Default is 1 second.

RetryDelegatingHandler(HttpMessageHandler, int, TimeSpan?)

Initializes a new instance of the RetryDelegatingHandler class with the specified inner handler.

public RetryDelegatingHandler(HttpMessageHandler innerHandler, int maxRetries = 3, TimeSpan? initialDelay = null)

Parameters

innerHandler HttpMessageHandler

The inner handler which is responsible for processing the HTTP response messages.

maxRetries int

The maximum number of retry attempts. Default is 3.

initialDelay TimeSpan?

The initial delay before the first retry. Default is 1 second.

Properties

InitialDelay

Gets the initial delay before the first retry. Each subsequent retry doubles the delay.

public TimeSpan InitialDelay { get; }

Property Value

TimeSpan

MaxRetries

Gets the maximum number of retry attempts.

public int MaxRetries { get; }

Property Value

int

Methods

SendAsync(HttpRequestMessage, CancellationToken)

Sends an HTTP request to the inner handler to send to the server as an asynchronous operation.

protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

Parameters

request HttpRequestMessage

The HTTP request message to send to the server.

cancellationToken CancellationToken

A cancellation token to cancel operation.

Returns

Task<HttpResponseMessage>

The task object representing the asynchronous operation.

Exceptions

ArgumentNullException

The request was null.

OperationCanceledException

The cancellation token was canceled. This exception is stored into the returned task.