Task parallelism with TPL
As mentioned earlier, task parallelism happens when dealing with parallel invocations of multiple methods/function. Within the .NET Framework, this can be obtained with the invocation of the Parallel.Invoke
method, which needs to have as a parameter all parallelizable actions as a whole. Most techniques applicable here are also applicable in asynchronous programming with the Task
or the TaskFactory
class. So reading Chapter 4, Asynchronous Programming is mandatory to get the best of task parallelism.
The Parallel.Invoke
method simply takes multiple remote methods to call procedures in a parallel way by accepting a System.Action
array. Here is an example:
static void Main(string[] args) { //short form with named methods ...
Get Learning .NET High-performance Programming 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.