Debugging Tools For Parallel Tasks

10/10/2010 3:49:18 PM
Visual Studio 2010 introduces two useful tool windows that you can use for debugging purposes when working on both parallel tasks and loops. To understand how such tooling works, consider the following code that creates and starts three tasks:
Sub CreateSomeTaks()
Dim taskA = Task.Factory.StartNew(Sub() Console.WriteLine("Task A"))
Dim taskB = Task.Factory.StartNew(Sub() Console.WriteLine("Task B"))
Dim taskC = Task.Factory.StartNew(Sub() Console.WriteLine("Task C"))
End Sub

Place a breakpoint on the End Sub statement and run the code. Because the tasks work in parallel, some of them maybe running at this point and other maybe not. To understand what is happening, you can open the Parallel Tasks tool window (select Debug, Windows, Parallel Tasks if not already visible). The window shows the state of each task, as represented in Figure 1.

Figure 1. The Parallel Tasks tool window.

Among the other information, the window shows the task ID, the status (that is, if it is running, scheduled, waiting, dead-locked or completed), the delegate that is making the actual job (in the Task column) and the actual thread that refers to the task. Next you can take advantage of the Parallel Stacks tool window (which can be enabled via Debug, Windows, Parallel Stacks) that shows the call stack for threads and their relationships. Figure 2 shows an example.

Figure 2. The Parallel Stacks window.

For each thread the window shows a information that you can investigate by right clicking on each row.

Top 10
NAS Devices: The Storage Centers (Part 1) - Buffalo LinkStation Pro 2TB, Freecom SilverStore 2-Drive NAS 2TB
Network Programming with Windows Sockets : A Socket Message Receive Function
Windows 7 : Maintaining Your System Configuration (part 3) - Configuring User Profiles, Environment Variables, and Startup and Recovery
Installing Windows Server 2008 R2 and Server Core : Managing and Configuring a Server Core Installation
Windows Azure : Common uses for worker roles (part 1)
IIS 7.0 : Hosting Application Development Frameworks - Hosting ASP Applications & Hosting PHP Applications
Exchange Server 2007 : Backup and Recover Data (part 2) - Backup and Recovery with Server 2008
Flora - Nature - Photo Expert (Part 4) - Viewpoint
Customizing Hardware Device Settings
Great Business Apps for Your iPad/iPod/iPhone : Car Butler, List n Do, Magnifying Glass with Light, WorkSnug
Most View
Windows 7 :Navigating Your Computer with the Address Bar (part 1) - Accessing Locations on Your Computer
IIS 7.0 : Implementing Access Control - Authentication (part 4)
Java EE 6 : Servlet Development and Deployment - Request forwarding and response redirection
Securing Windows Server 2008 in the Branch Office
CPU System Workshop (Part 1)
Mobile Commerce Applications, Part 2
SharePoint 2010 : Securing SharePoint’s SQL Server Installation
Java EE 6 with GlassFish 3 Application Server : Developing our first JSP
Understanding and Using Windows Server 2008 R2 UNIX Integration Components (part 1)
Shoot Your Best-Ever Portraits (Part 1)
Windows 7 : Protecting Your Computer While Browsing (part 5)
The ASP.NET AJAX Infrastructure
Windows 7 : Detecting and Resolving Computer Problems (part 1) - Solving the Tough Problems Automatically
One-week Experience With LG Optimus L7
SQL Server 2008 R2 : Creating and Managing Indexes - Types of Indexes
Choosing The Right Parts For Your Build (Part 5) - Choosing your case & Picking the right storage
Microsoft Content Management Server : Building SharePoint Web Parts - The SharePoint MCMS Navigation Control, Creating the Web Part Project
Building Your First Windows Phone 7 Application (part 1) - Creating a Windows Phone Project
Avanquest Fix-It Utilities 12.0
Photo Rescuse