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. Using the methods shown at the beginning of this section for retrieving thread information, simulate intensive processing and the measuring of 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:

Sub ClassicForEachTest()    Dim allFiles = IO.Directory.        EnumerateFiles("C:\users\alessandro\pictures")    For Each fileName In allFiles        Console.WriteLine(fileName & GetThreadId()) ...

Get Visual Basic 2015 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.