The Tasks Window is one of the nicest things which was introduced with Visual Studio 2013 Preview. This window will be very useful when debugging asynchronous code.
In Visual Studio 2010 and Visual Studio 2012 there is a windows called Parallel Tasks. You can view the Parallel Tasks window either by typing Parallel Tasks in Quick Launch or by going to Debug -> Windows -> Tasks when you are debugging the code. This window is renamed to Tasks in Visual Studio 2013 Preview.
|Parallel Tasks Window|
You can access Task window in Visual Studio 2013 Preview by typing Tasks in Quick Launch or by going to Debug -> Windows -> Tasks and again that's when you are debugging the code. That's same as in Visual Studio 2010 and 2012.
Let’s take a look at the following code snippet.
Here I have a button and in it’s click event I am calling DoWork method asynchronously and from DoWork I am calling GetString method asynchronously. Here the awaited Task.Yield() is used to leave the current async code and to return back to the current context.
Now let’s put some breakpoints in the code. I have put two breakpoints in DoWork method and in GetString method. Now this is what you will see in the Tasks window.
|No Tasks in Tasks Window|
There are no tasks created yet and let’s keep debugging. The moment control leaves the Task.Yield() in DoWork method, two tasks are created.
|Tasks Window on await GetString|
The task which the button click event is awaiting on is active. The task which is bound to Button click is scheduled to run. Again let’s keep debugging.
When the control comes to the line after Task.Yield() in GetString method this is what you will see in Tasks window.
|Tasks Window after leaving Task.Yield in GetString|
Now another task is created. Two tasks are active, the task which the Button click event is awaiting on and the task which the DoWork method is awaiting on. Still the task which is bound to Button click is scheduled to run.
And finally when you keep debugging and when the control leaves the line where the Button click calls the DoWork method, you can see that the task which is bound to Button click is now active.
|Tasks Window on leaving DoWork|