Tweaking the parameters of a PLINQ query
This recipe shows how we can manage parallel processing options using a PLINQ query and what these options could affect during query execution.
Getting ready
To step through this recipe, you will need Visual Studio 2012. There are no other prerequisites. The source code for this recipe can be found in BookSamples\Chapter7\Recipe3
.
How to do it...
To understand how to manage parallel processing options using a PLINQ query and their effects, perform the following steps:
Start Visual Studio 2012. Create a new C# Console Application project.
In the
Program.cs
file add the followingusing
directives:using System; using System.Collections.Generic; using System.Linq; using System.Threading;
Add the following code snippet below the
Main
method:static string EmulateProcessing(string typeName) { Thread.Sleep(TimeSpan.FromMilliseconds(new Random(DateTime.Now.Millisecond).Next(250,350))); Console.WriteLine("{0} type was processed on a thread id {1}",typeName, Thread...