I have a solution that creates multiple I/O based tasks and I\'m using Task.WhenAny() to manage these tasks. But often many of the tasks will fail due to network issue or reques
I believe it would be easier to retry within the tasks, and then replace the Task.WhenAny
-in-a-loop antipattern with Task.WhenAll
E.g., using Polly:
var tasks = new List>();
var policy = ...; // See Polly documentation
foreach(var item in someCollection)
tasks.Add(policy.ExecuteAsync(() => GetSomethingAsync()));
await Task.WhenAll(tasks);
or, more succinctly:
var policy = ...; // See Polly documentation
var tasks = someCollection.Select(item => policy.ExecuteAsync(() => GetSomethingAsync()));
await Task.WhenAll(tasks);