Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Polly RetryForever isn't retrying

I’m, trying to check a simple RetryForever of Polly

 class Program
    {
        public static void Main()
        {
               
            int i = 0;
            var _retryPolicy = Policy
           .Handle<Exception>()
           .RetryForever();

            _retryPolicy.Execute(async () =>
            {
                Console.WriteLine(i);
                i++;
                    int.Parse("something");
            });

            Console.ReadLine();
        }
    }

A you can see I’ve created a variable i to track the number of the exestuations

Excepted Result:
print i = 0, 1, 2 etc

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Actual Result:
print i = 0

Thank You

>Solution :

I’ve checked your code and you had right, its stops on 0.

But when i removed async keyword (u didnt have any async operation here) the code runs correct.

So, try this:

using Polly;

int i = 0;
var _retryPolicy = Policy
  .Handle<Exception>()
  .RetryForever();

_retryPolicy.Execute(() =>
{
  Console.WriteLine(i);
  i++;
  int.Parse("something");
  return Task.CompletedTask;
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading