Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.
/ Retry Public archive

Library to assist implementing application retry logic

License

Notifications You must be signed in to change notification settings

pbolduc/Retry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Archived, use Polly.

Retry

Library to assist implementing application retry logic. RetryPolicy/ShouldRetry taken from Windows Azure SDK for .NET (https://github.com/WindowsAzure/azure-sdk-for-net).

More samples will be added to the source code.

Simple example with no retry:

RetryPolicy noRetryPolicy = () =>
{
    return (int retryCount, Exception exception, out TimeSpan retryInterval) =>
    {
        retryInterval = TimeSpan.Zero;
        return false;
    };
};

Action action = () => { /* some action to retry */ };
action.InvokeWithRetry(noRetryPolicy);

Simple example with 100ms delay between retries with up to 5 retries:

RetryPolicy simpleRetryPolicy = () =>
{
    return (int retryCount, Exception exception, out TimeSpan retryInterval) =>
    {
        retryInterval = TimeSpan.FromMilliseconds(100);
        return retryCount < 5;
    };
};

Action action = () => { /* some action to retry */ };
action.InvokeWithRetry(simpleRetryPolicy);

Func<int> func = () => { /* some action to retry */ return 0; };
int result = func.InvokeWithRetry(simpleRetryPolicy);

You can also provide an ManualResetEventSlim to cancel any wait and throw the last error:

SqlConnection connection = ...
// try to open a connection to the database 	
Action action = connection.Open;
ManualResetEventSlim cancel = new ManualResetEventSlim(false);
action.InvokeWithRetry(retryPolicy, cancel);

// on another thread, cancel any current executing wait
cancel.Set();

About

Library to assist implementing application retry logic

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages