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 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.