Parallel.ForEach(myCollection, async item =>
This is almost certainly not what you want. The delegate is of type Action<T> , and therefore the anonymous method is an async void method. This means that it is starting, and you cannot check its status, except by checking any of its side effects. In particular, if something goes wrong, you cannot catch and handle the exception.
If all else fails, the results will be added to the bag as they are completed. Until nothing completes, bag will be empty.
In contrast, OrderByCompletion returns an IEnumerable<Task<T>> , which immediately contains tasks that are still not completed. You can await fifth element and continue when all five tasks are completed. This can be useful when, for example, you want to run a large number of tasks and periodically update the form to show progress.
The third option you gave, ForEachAsync , will behave like ForEach , except that it will do everything right, without the problems mentioned above.
hvd
source share