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.
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.
For each thread the window shows a information that you can investigate by right clicking on each row.