Using Parallel LINQ (PLINQ)
In this section, you will learn how to convert your sequential LINQ queries into parallel LINQ using PLINQ. Take a look at the following code:
var productNames = GetProductNames();
var names = from name in productNames
where name.Length > 8
select name;
The preceding code calls the GetProductNames
method and stores the results in the productNames
variable. A LINQ statement is then performed on the productNames
list to extract a list of all product names greater than eight characters in length. The result of this LINQ statement is then stored in the names
variable.
The following code is identical to the preceding code, except we have modified it so that it operates in parallel across multiple processors:
var productNames = GetProductNames();
var names = from name in productNames.AsParallel()
...