My requirement is quite weird.
I have SomeMethod()
which calls GetDataFor()
.
public void SomeMethod()
{
for(int i = 0
I would instead add each of the tasks to a collection and then await on the entire collection AFTER the loop.
Awaiting inside of a loop like that will create lots of continuations and more overhead than desirable including waiting for each call to finish before continuing the loop I believe.
Take a look at awaiting Task.WaitAll instead.
If instead the value of each task is important to process then look at awaiting Task.WhenAll and then read the results of each Task into your return collection.