Debugging parallel code
With the prevalence of multi-core CPUs, we are seeing more and more applications taking advantage of parallel processing to improve performance. .NET Framework 4.0 added a number of features such as Task Parallel Library (TPL) and Parallel LINQ (PLINQ) to make the development of applications that take advantage of multi-core CPUs much simpler.
The debugging experience for threaded applications in Visual Studio has got better with each release, and VS2013 is no exception. Let's take a look at what is available.
Getting ready
Start a premium edition Visual Studio 2013 and create a new C# console application. For this recipe, call the application ParallelDebugging
.
How to do it…
In order to debug the parallel code, perform the following steps:
Use the following code to populate the body of
Program.cs
. It's a pretty simple program that starts a parallelfor
loop, which in turn calls a method that performs meaningless calculations intended to keep the CPU busy.class Program...