There are two annotated frames with the
[Async Call] label. The first annotated frame adds the frame for the
RefreshDataSource method and the second one provides the frame for the
The State of All Tasks
The Parallel Tasks window has been renamed the Tasks window in VS2013 and is enhanced to show the state of all the tasks and promises scheduled, running, and waiting in an application. One of the main problems with asynchronous code is that you can easily lose control of the different pieces that are scheduled and running in an application. For example, you can have a task that takes a long time to run, but you don't realize this because it doesn't block the UI. However, there is still an underlying impact in the resources consumed by the application and its long running task. You may only notice that there is a problem because the application consumes more battery than expected or you hear the CPU fans running at full speed in a laptop for a long time.
Instead of monitoring the sound of your CPU fans, you can take advantage of the new features included in the Tasks window to better appreciate what is occurring with your code. Figure 3 shows the information displayed by the Tasks window in the same
GetAll method debugging session that is running as a result of two chained asynchronous method calls. The Tasks window displays all the tasks that are currently running or are scheduled to run, which represent asynchronous operations. Notice that both the tasks that are running the
OnLaunched and the
RefreshDataSource methods are in the
Awaiting status because the task that is running the
GetAll method is
Active. You will notice that the Task column displays
Async: <GetAll>d__2 for the active task, indicating that it is a lambda function that is located in the
Figure 3: The Tasks window displaying the tasks that are currently running or are scheduled to run, which represent asynchronous operations.
If you hover over the location column for an active task, VS2013 displays the call stack information including the frames for the asynchronous calls (see Figure 4). Thus, you can easily visualize the same information that the enhanced Call Stack window displays when you are located in this task, but you don't need to leave the Tasks window.
Figure 4: The Tasks window displaying the call stack information that includes the asynchronous calls and frames that ended up in the
If you hover over the
Awaiting status of one of the tasks, VS2013 displays a tooltip indicating the task that your task is waiting for. For example, Task ID 5 (the
RefreshDataSource method) is waiting for Task ID 3 (the
GetAll method), as you can see in Figure 5.
Figure 5: The Tasks window displaying the task that Task ID 5 is waiting for in a tooltip.
The Tasks window includes two new columns:
Start Time and
Duration, with both values expressed in seconds. The
Start Time column displays the time when the task was created relative to the time that you started debugging. The
Duration column displays how long the task has been running. By paying attention to the values in these new columns, you can easily identify tasks that have been running for longer than expected. In fact, you can detect tasks that shouldn't be running anymore and that might have defects, making them continue executing code unnecessarily.
The new features introduced in Visual Studio 2013 in combination with Windows 8.1 solve many of the biggest problems encountered when debugging asynchronous code. With the improvements in the Call Stack window, you can easily navigate through your session and will feel more like you are debugging synchronous code instead of asynchronous code. The only drawback is that you cannot use the features with Windows 8 and you are forced to upgrade to Windows 8.1. However, it is important to note that you can still develop apps that target both Windows 8 and 8.1.
Gaston Hillar is a frequent contributor to Dr. Dobb's.