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 Parallel.Invoke(Method1, Method2, Method3); //short form with anonymous methods Parallel.Invoke( () => { }, () => { }, () => { }); } static void Method1() { } static void Method2() { } static void Method3...