Using the Tasks Window
In managed code, you can use the Tasks window when you work with System.Threading.Tasks.Task objects or with the await and async keywords (Await and Async in VisualBasic). For more information about tasks in managed code, see Parallel Programming in the .NET Framework.
In native code, you can use the Tasks window when you work with task groups, parallel algorithms, asynchronous agents, and lightweight tasks. For more information about tasks in native code, see Concurrency Runtime.
You can use the Tasks window whenever you break into the debugger. You can access it on the Debug menu by clicking Windows and then clicking Tasks. The following illustration shows the Tasks window in its default mode.
The columns in the Tasks window show the following information.
Shows which tasks are flagged and lets you flag or unflag a task.
A yellow arrow indicates the current task. The current task is the top-most task on the current thread.
A white arrow indicates the breaking task, that is, the one that was current when the debugger was invoked.
The pause icon indicates a task that has been frozen by the user. You can freeze and unfreeze a task by right-clicking it in the list.
A system-provided number for the task. In native code, this is the address of the task.
The current state (scheduled, active, deadlocked, waiting, or completed) of the task. A scheduled task is one that has not yet been run and, therefore, does not yet have a call stack, assigned thread, or related information.
A active task is one that was executing code before breaking in the debugger.
A waiting task is one that is blocked because it is waiting on an event to be signaled, a lock to be released, or another task to finish.
A deadlocked task is a waiting task whose thread is deadlocked with another thread.
Hover over the Status cell for a deadlocked or waiting task to see more information about the block.
The time at which the task became active.
The number of seconds that the task has been active.
The time at which the task completed.
The current location in the call stack of the task. Hover over this cell to see the entire call stack for the task. Scheduled tasks do not have a value in this column.
The initial method and any arguments that were passed to the task when it was created.
The ID of the task that created this task. If this is blank, the task has no parent. This is only applicable for managed programs.
The ID and name of the thread on which the task is running.
The status of the task when it completed. The return status values are Success, Cancelled, and Error.
For managed code, the application domain in which the task is executing.
For native code, the address of the task_group object that scheduled the task. For asynchronous agents and lightweight tasks, this column is set to 0.
The ID of the process that the task is running on.
For managed code, the task status. By default, this column is hidden. To display this column, open the context menu for one of the column headers. Choose Columns, AsyncState.
You can add columns to the view by right-clicking a column heading and then selecting the columns you want. (Remove columns by clearing the selections.) You can also reorder columns by dragging them left or right. The column shortcut menu is shown in the following illustration.
To sort tasks by column criteria, click the column header. For example, by clicking the ID column header, you can sort the tasks by task ID: 1,2,3,4,5 and so on. To reverse the sort order, click the column header again. The current sort column and sort order is indicated by an arrow on the column.
You can group tasks based on any column in the list view. For example, by right-clicking the Status column header and then clicking Group by Status, you can group all tasks that have the same status. For example, you could quickly see waiting tasks so that you could focus on why they are blocked. You can also collapse a group that is not of interest during the debug session. In the same manner, you can group by the other columns. A group can be (un)flagged just by clicking the button next to the group header. The following illustration shows the Tasks window in grouped mode.
(This view is available for managed code only.) By right-clicking a column heading and then clicking Parent Child View, you can change the list of tasks to a hierarchical view, in which every child task is a sub-node that can be displayed or hidden under its parent. The following illustration shows the tasks in parent-child view.
You can flag the thread the task on which a task is running by selecting the task list item and then choosing Flag from the context menu, or by clicking the flag icon in the first column. If you flag several tasks, you can then sort on the flag column to bring all the flagged tasks to the top so that you can focus just on them. You can also use the Parallel Stacks window to view only flagged tasks. This lets you filter out tasks that you are not interested in for debugging. Flags are not persisted between debugging sessions.
You can freeze the thread on which a task is running by right-clicking the task list item and then clicking Freeze Assigned Thread. (If a task is already frozen, the command is Thaw Assigned Thread.) When you freeze a thread, that thread will not execute when you step through code after the current breakpoint. The Freeze All Threads But This command freezes all threads except the one that is executing the task list item.
The following illustration shows the other menu items for each task.