Our great sponsors
-
Polly
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.