TPL: paralllel foreach exception handling - stop all tasks

sfun28
sfun28 used Ask the Experts™
on
Folks,

Lets say I have a Parallel.ForEach...1000 items in my enumeration and a failure somewhere after 100 items are processed.  How can I tell .net to STOP processing the rest of the items and just throw the AggregateException?

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Not sure i understand perfecly your question.... if you could send us your code, i'it could help

what about this;

for each 100
try
your code
catch ex as aggregateexception
throw
end try

Author

Commented:
sdrouins - Its still not clear to me from that and other documentation.  When an exception is thrown on a thread generated from the parallel foreach, is the AggregateException thrown immediately?  What happens to the theads that are running?  how about the threads that haven't completed?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial