Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 3.59 KB

README.md

File metadata and controls

46 lines (33 loc) · 3.59 KB

Parallel.ForEachAsync Exceptions

Parallel.ForEachAsync is a very useful tool for running code in parallel. But what happens when an exception is thrown inside the loop?

By default, the following things happen:

  1. If we "await" ForEachAsync, then we get a single exception (even if exceptions are thrown in multiple iterations of the loop).
  2. The loop short-circuits -- meaning not all items are processed.

This code explores both of these issues in a couple of different ways.

For slides and code samples on Parallel.ForEachAsync (and other parallel approaches), you can take a look at the materials from my full-day workshop on asynchronous programming: https://github.com/jeremybytes/async-workshop-2022. (These materials use .NET 6.0. Updates for .NET 8.0 are coming in a few months.) For announcements on public workshops, check here: https://jeremybytes.blogspot.com/p/workshops.html.

Articles

Projects