LINQ uses lazy evaluation so uniqueExceptions in the last example will be enumerated and processed for distinct elements 3 times - for the .Count(), .First() and the final return. You should just call .ToList() after .Distinct() to get an actual List of exceptions.
There's also the Polly library which handles retries, timeouts, circuit breakers and many other resiliency situations in a well built API.
LINQ uses lazy evaluation so
uniqueExceptionsin the last example will be enumerated and processed for distinct elements 3 times - for the.Count(),.First()and the final return. You should just call.ToList()after.Distinct()to get an actualListof exceptions.There's also the Polly library which handles retries, timeouts, circuit breakers and many other resiliency situations in a well built API.
github.com/App-vNext/Polly