O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required