Parallel.ForEach Loop

Similarly to For loops, the Parallel class offers an implementation of For..Each loops for iterating items within a collection in parallel. Still taking advantage of methods shown at the beginning of this section for retrieving thread information, simulate intensive processing and measuring elapsed time; imagine you want to retrieve the list of image files in the user level Pictures folder simulating an intensive processing over each filename. This task can be accomplished via a classic For..Each loop as follows:

image

The intensive processing simulation still relies on a single thread and on a single processor, thus it will be ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.