Turtle.Retry 2.0.0

.NET Standard 2.0
NuGet\Install-Package Turtle.Retry -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
dotnet add package Turtle.Retry --version 2.0.0
<PackageReference Include="Turtle.Retry" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Turtle.Retry --version 2.0.0
#r "nuget: Turtle.Retry, 2.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Turtle.Retry as a Cake Addin
#addin nuget:?package=Turtle.Retry&version=2.0.0

// Install Turtle.Retry as a Cake Tool
#tool nuget:?package=Turtle.Retry&version=2.0.0


What does it do?

Turtle saves you from writing your logic to retry an action when it fails. It allows you to fine tune the behavior.

Why Turtle?

A turtle might be slow, but it is determined to get where it wants to be!


var result = Retry.This(() =>

This will repeat the Action passed in This() every 100ms for a maximum of 5 tries as long as the action throws an exception. result contains the CompletionState. The CompletionState is an enum with the following values: Failed, Aborted, Success.

Retry.This(() =>
    return false;

This will repeat the Func<bool> pass in This() every 100ms for a maximum of tries as long as the Func return false.

Retry.This(() => Console.WriteLine("Hello"),
        () => true)
This uses a predicate to determine if the try was successful.

Retry.This(() =>
    return false;
.Using(new LimitedExponentialBackoffRetryStrategy
    BaseDelay = TimeSpan.FromMilliseconds(50),
    MaxDelay = TimeSpan.FromSeconds(5)

This example uses a limited exponential backoff strategy. The time wait between tries increases exponentially.

Different RetryStrategies can be easily created.

var tokenSource = new CancellationTokenSource();
var t = Retry.This(() =>

It works with Tasks as well.

Control behavior based on the exception

It is possible to define how Turtle.Retry will behave in case of an exception. You can do this by passing an implementation of IExceptionBehavior like this:

Retry.This(() => action)
.OnException(new MyExceptionBehavior()

This interface is fairly simple. Just implement the OnException method, and return the appropriate AfterExceptionBehavior. AfterExceptionBehavior is an enum with the following values: Retry, Rethrow, Abort. Retry will result in another try if MaximumNumberOfTries has not been reached yet, Abort will stop the Retry process and return CompletionState.Aborted. Retrow instructs Turtle.Retry to rethrow the exception and therefore stop the Retry process.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 17,484 2/28/2018
1.1.1 1,258 10/26/2016
1.1.0 1,070 9/30/2016
1.0.1 1,136 7/12/2016
1.0.0 985 5/16/2016