'Is there a "limit" to Task.WhenAll?

If I need to perform IO-operations in a loop, I can create the Tasks and them await them all. Something like this:

var tasks = new List<Task>();
for (var dataToProcess in listOfData) {
    tasks.Add(DoSomeIOAsync(dataToProcess));
}

await Task.WhenAll(tasks);

How can I reason about what a reasonable number of dataToProcess in listOfData is?

If DoSomeIOAsync is async, then the thread used would be returned while waiting for the IO. So no risk for thread pool starvation I guess?

Is it the overhead of having a large amount of Task state machines in memory that might be a problem?

Are there some guidelines that I can use to reason about this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source