Say I want to make parallel API post requests.
In a for loop I can append the http post call into a list of tasks, (each task invoked using Task.Run) and then wait for all to finish using await Task.WhenAll
. Thus the control will go to caller while waiting for the network request to complete. Effectively the API request will be made in parallel.
Similarly I can use Parallel.ForEachAsync
which will automatically do the WhenAll
and return control to caller. So I want to ask whether ForEachAsync
is a replacement to a plain for loop list (async await Task.Run) and WhenAll
?