Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
How to make conditional WaitAndRetry or WaitAndRetryForever depending on the exception?

Here is my try:

private Policy retryPolicy { get; } = Policy
    .Handle<IOException>()
    .WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
private Policy bigFilePolicy { get; } = Policy
    .Handle<UnauthorizedAccessException>()
    .WaitAndRetryForeverAsync(retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));

retryPolicy.ExecuteAsync(() => bigFilePolicy.ExecuteAsync(command));  

I am trying to make a retry policy for an automatic file upload system. When the file is too big, it takes some time to be dropped in the folder and while it loads, my program gives an unauthorized access exception, in such cases I am thinking of allowing WaitAndRetryForever for the big files. Otherwise, if it gets other exceptions it should not retry forever.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

To mix policies together you need to call Policy.Wrap/Policy.WrapAsync. For example, you could do:

var exponentialBackoffPolicy = Policy.WrapAsync(retryPolicy, bigFilePolicy);

Or even:

var exponentialBackoffPolicy = retryPolicy.WrapAsync(bigFilePolicy);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!