Running Tasks with Parallel.Invoke

The first way for running tasks in parallel is calling the Parallel.Invoke shared method. This method can receive an array of System.Action objects as parameter, so each Action is translated by the runtime into a task. If possible, tasks are executed in parallel. The following example demonstrates how to perform three calculations concurrently:

image

In the example the code takes advantage of statement lambdas; each of them is translated into a task by the runtime that is also responsible for creating and scheduling threads and for scaling tasks across all available processors. If you run the code you can see how the ...

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.