Channels ▼
RSS

Tools

Visual Studio 2013 Asynchronous Debugging


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 OnLaunched method. Now, you can easily navigate to the methods that generated the asynchronous calls and understand the asynchronous code flow while debugging. The additional frames really increase productivity when debugging asynchronous code. If you compare the debugging experience with the same code in Visual Studio 2012, you will be motivated to upgrade to Windows 8.1 just to have this access to this feature. (It was the only reason I upgraded to Windows 8.1!) Note that the new Call Stack window is also available in C++ and JavaScript.

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 GetAll method.

injection
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.

injection
Figure 4: The Tasks window displaying the call stack information that includes the asynchronous calls and frames that ended up in the GetAll method.

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.

injection
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.

Conclusion

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.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video