Retry patterns in applications and services

private int retryCount = 3
private readonly TimeSpan delay = TimeSpan.FromSeconds(5);

public async Task OperationWithBasicRetryAsync()
int currentRetry = 0;

for (;;)
// Call external service.
await TransientOperationAsync();

// Return or break.
catch (Exception ex)
Trace.TraceError("Operation Exception");

if (currentRetry > this.retryCount || !IsTransient(ex))
// If this isn't a transient error or we shouldn't retry,
// rethrow the exception.

// Wait to retry the operation.
// Consider calculating an exponential delay here and
// using a strategy best suited for the operation and fault.
await Task.Delay(delay);

// Async method that wraps a call to a remote service (details not shown).
private async Task TransientOperationAsync()
[FixedDelayRetry(5, "00:00:10")]
public static async Task Run([EventHubTrigger("myHub", Connection = "EventHubConnection")] EventData[] events, ILogger log)
// ...




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

CKeditor5 React editor how to add and remove tools

Refactor TodoMVC with Redux Starter Kit

Avoiding Common Mistakes, clip on dentures

Rethinking the design-to-development process

Comparison In ReactJS and React Native

Learn React  —  by building Stopwatch

Authentication Handling in React

Choosing the right Node.js Framework: Next, Nuxt, Nest?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tomasz Dobrowolski

Tomasz Dobrowolski

More from Medium

Getting started with Azure and VMs

final screen in the sign up

Easy way to use Azure Application Gateway for an Intranet Application

Manage Microsoft 365 tenant’s configuration with Microsoft365DSC: Part one

Keda and Helm