Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Failsafe.Tests Add project files. Feb 8, 2019
Failsafe Remove years from copyright Feb 17, 2019
.gitattributes Add .gitignore and .gitattributes. Feb 8, 2019
.gitignore
Changelog.md Add project files. Feb 8, 2019
Failsafe.sln Add project files. Feb 8, 2019
License.txt Add project files. Feb 8, 2019
Readme.md Add project files. Feb 8, 2019
appveyor.yml Add appveyor.yml Feb 8, 2019
favicon.png Add favicon Feb 8, 2019

Readme.md

Failsafe

Build Tests NuGet NuGet

Failsafe is a library that provides a fluent interface for retrying an operation.

Download

Features

  • Retry on specific, derived or any exception
  • Match exceptions with a predicate
  • Limit number of retries
  • Configurable delay between retries
  • Supports synchronous and asynchronous execution
  • Fluent interface
  • Targets .NET Framework 4.5+ and .NET Standard 2.0+
  • No external dependencies

Usage

Basic example

var result = Retry.Create().CatchAnyException().Execute(FlakyMethod);

Retry only on specific exceptions

var result = Retry.Create()
	.Catch<InvalidOperationException>() // match specific exception
	.Catch<IOException>(true) // match specific exception and derived from it
	.Catch<FileNotFoundException>(false, ex => ex.FileName == "file.txt") // match specific exception and use predicate
	.Execute(FlakyMethod);

Configure retry limit and delay

var result = Retry.Create()
	.CatchAnyException()
	.WithMaxTryCount(15) // no more than 15 attempts
	.WithDelay(TimeSpan.FromSeconds(0.2)) // wait 0.2s before trying again
	.Execute(FlakyMethod);

Libraries used