DEV Community

Discussion on: C#, Task.WhenAll vs Parallel.ForEach

Collapse
 
plondhe profile image
Prakhar Londhe

There are certain drawbacks I can see with this:

  1. In the second method, where you use Parallel.ForEach, that is highly dubious. You are essentially making synchronous calls from different threads. It is not the same as async/await, where the threads are free to do other work and some other thread is captured only when the response is ready ( be it from http or db ).
  2. If you change the order of the parallel.foreach and task.whenall, you will most probably notice that now task.WhenAll is taking less time. This can mostly be attributed to request caching, as well as usage of pre-existing connection the second time.