Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. From version 6.0.1, Polly targets .NET Standard 1.1 and 2.0+.
Look into using a resilience framework. These tools have policies for retry, circuit breakers, timeouts, etc. A preferred framework for .Net is The Polly Project. I've used it in dealing with third-party APIs that timeout under heavy load. It can also be used to deal with database connectivity issues. The retry loops are configurable for the number of retries and the wait time. There are similar products for most languages. You can roll your own with a loop around a try/catch block where the catch increments the retry count and throws if the retry limit is exceeded.
1 project | reddit.com/r/csharp | 25 Jun 2022
RateLimiter in Dotnet Core Web Application
1 project | reddit.com/r/aspnetcore | 28 Dec 2021
RateLimiter in DotNet Core Web Application
1 project | reddit.com/r/dotnetcore | 27 Dec 2021
How to use Circuit Breaker to manage third party apis ?
1 project | reddit.com/r/microservices | 27 Nov 2021
test internet connection while using api
1 project | reddit.com/r/csharp | 16 Oct 2021