Parallel Invocation

Invoking a single task suffices in many cases, but it often makes sense to achieve parallelism by running multiple tasks. Although you can simply create multiple tasks, some higher levels of abstraction exist in the TPL. One such abstraction is Parallel.Invoke, which takes an array of Action delegates to invoke in parallel. You can think of each such action resulting in a task being created. Only when all the tasks complete, the Parallel.Invoke call returns. This said, Parallel.Invoke makes no guarantees that the actions really run in parallel because of the way scheduling works. (The same worker might pick up all the actions, causing them to run sequentially.)

An example of Parallel.Invoke is shown here:

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.