Giter VIP home page Giter VIP logo

microsoft / retryoperationhelper Goto Github PK

View Code? Open in Web Editor NEW
37.0 18.0 16.0 1.17 MB

Retry Operation Helper is a simple class which encapsulates the retry of any given piece of C# .NET logic a given number of times before failing, as well as running an optional function on failure. It is useful for any call where transient exception are possible, for example, making a call to a remote database or service.

License: MIT License

C# 9.25% PowerShell 90.06% Batchfile 0.69%

retryoperationhelper's Introduction

RetryOperationHelper

Retry Operation Helper is a simple class which encapsulates the retry of any given piece of C# .NET logic a given number of times before failing, as well as running an optional function on failure. It is useful for any call where transient exception are possible, for example, making a call to a remote database or service.

#Licenses Retry Operation Helper is licensed under the MIT license.

RetryOperationHelper uses third-party libraries or other resources that may be distributed under licenses different than RetryOperationHelper.

#Demo Demo Chart

#Usage Create a RetryOperationHelper object and pass it a Func<> object containing whatever piece of logic you need retried. From then on, that logic will be retried the given number of times before the exception is thrown back to the original thread. For example, the code goes from this:

await sqlExecutionEngine.ExecuteSqlOperation();

to

Func<Task> func = () => sqlExecutionEngine.ExecuteSqlOperation();
await RetryOperationHelper.ExecuteWithRetry(func, 3); 

It is useful for code calling databases or anywhere transient issues may be present. Always pass atomic pieces of logic, usually a single call, given the entire code block will be retried if any part of it throws an exception.

#Microsoft Open Source Code of Conduct This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

retryoperationhelper's People

Contributors

andrewcoll avatar conork20 avatar microsoft-github-policy-service[bot] avatar msftgits avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

retryoperationhelper's Issues

Losing context

When retrying operations on Windows Forms, the RetryOperationHelper is loosing the UI thread:

InvalidOperationException: Cross-thread operation not valid: Control 'label1' accessed from a thread other than the thread it was created on.

Repro:

private async void button1_Click(object sender, EventArgs e)
{
    Func<Task> func = () => UpdateLabel();
    await RetryOperationHelper.ExecuteWithRetry(func, 3);
}

int counter;

private async Task UpdateLabel()
{
    await Task.Delay(500);

    if (counter++ < 1)
        throw new Exception("test");

    label1.Text = DateTime.Now.ToString();
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.