I have some code I'm going to parallelize. It currently looks something like this:
foreach (var item in collection) { if (error) { throw new Exception(); } } The exception and its stack trace are saved in a log file.
After parallelization, it would look like this:
Parallel.ForEach(collection, item => { if (error) { throw new Exception(); } }); - How will this exception stop the parallel execution of the other items? Is there a way to stop all other executions once an error is encountered in one the loop threads?
- How will this influence the exception stack trace?