Ex1Task1_ParallelForEach()
... End Sub
17. Build and run the application. 18. You will again observe that the employees are not necessarily processed in order of their ID and because each loop is run in parallel, each iteration of the loop is run individually on whatever core is available. Also, since the application is utilizing all available cores the job is able to complete faster than when run in a serial manner. Figure 4 Output from parallel for…each implementation
Note: The Parallel Extensions Library also provides a useful Invoke() method, that allows parallel execution of anonymous methods or lambda expressions. To help illustrate how to use the Invoke method you will examine a common tree-walking algorithm and then see how it can be parallelized to reduce the total time needed to walk the entire tree. In this example you will walk an employee hierarchy and call the GetPayrollDeduction() method for each employee you encounter.
19. Replace the current method calls from Main(), with a call to Ex1Task1_WalkTree() method. This code instantiate the employee hierarchy and call the tree walker method. C# static void Main(string[] args) { ... // Methods to call
|