End Sub
Note: The calls to the Select(), OrderBy(), and Where() methods, which were previously being made on Enumerable, are now being made on ParallelEnumerable. Also notice that a call to AsParallel() has been added to the data source.
9. Build and run the application. 10. You should observe the LINQ query no longer performs the operations in a particular order. Also note that in this example the parallelized version completes in less time than the non-parallelized version (in this case, it completed in roughly half the time due to it being run on a dual-core machine; your results will vary based on the hardware you run this example on). Figure 14 Output from a parallelized LINQ query
Note: The operations are executed in parallel with as many operations occurring concurrently as the number of physical cores will allow.
Task 2 – Using the ParallelEnumerable Class’ Extension Methods to Parallelize LINQ As mentioned earlier, a more succinct way to take advantage of the Enumerable and ParallelEnumerable classes’ static LINQ methods is to use them as Extension methods. 1. Converting a non-parallelized LINQ query implemented using extension methods to a PLINQ query is straight forward. Replace the PLINQ query in the Main() method to match the following LINQ query: C# static void Main(string[] args) { ... // Methods to call
|