Piguy Piguy - 1 month ago 8
C# Question

How to handle exceptions in Parallel.Foreach?

I have a parallel.Foreach loop in my code and I am wondering how to handle exceptions. Should I catch and handle(e.g write to log) exceptions inside the loop or should I catch aggregate exception outside - encapuslate the loop in try/catch?

Best regards

Answer

This MSDN Article should answer your question. It's pretty simple.