var context = new Context();
context["retryCount"] = 0;
await GetResiliencyStrategy()
.ExecuteAsync(async (ct) =>
var r = (int)ct["retryCount"];
public async System.Threading.Tasks.Task Logic(int retry) {
throw new Exception("problem");
Console.WriteLine("Im Executing");
private IAsyncPolicy<int> GetResiliencyStrategy()
return Polly.Policy.Handle<Exception>(ex => !(ex is OperationCanceledException))
.WaitAndRetryForeverAsync(
sleepDurationProvider: (_, result, __) => TimeSpan.FromSeconds(5),
onRetryAsync: async (ex, retryCount, timeSpan, ct) =>
ct["retryCount"] = retryCount;
Console.WriteLine("\t\tsomething happened");
Polly.Policy.HandleResult<int>(r => r == 1)
.WaitAndRetryForeverAsync(
sleepDurationProvider: (_, result, __) => TimeSpan.FromSeconds(5),
onRetryAsync: async (result, retrycount, timespan, ct) =>
ct["retryCount"] = retrycount;
Console.WriteLine("Guideline validation processing finished. waiting " + timespan + " before next processing.");
await System.Threading.Tasks.Task.CompletedTask;