Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add automatic retry options for certain functions
#2
Try Polly.
Get: https://www.nuget.org/packages/Polly.Core/
Learn: https://www.pollydocs.org/

Example:
Code:
Copy      Help
// script "nuget Polly.cs"
/*/ nuget -\Polly.Core; /*/
using Polly;
using Polly.Retry;

//Create Polly object that executes "retry".
var ro = new RetryStrategyOptions(); //default options: max 3 retries, every 2 s
//var ro = new RetryStrategyOptions { MaxRetryAttempts = 10, Delay = TimeSpan.FromMilliseconds(100) }; //custom options

var retry = new ResiliencePipelineBuilder().AddRetry(ro).Build();

//example. Find window. On exception wait/retry several times.
var w = retry.Execute(() => wnd.find(0, "*Notepad"));
print.it(w);

//example. Activate window. On exception wait/retry several times.
retry.Execute(() => { w.Activate(); });


Messages In This Thread
RE: Add automatic retry options for certain functions - by Gintaras - 03-28-2024, 10:09 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)