Debugging Tools For Parallel 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.