Watching values in a thread with Parallel Watch window

Traditionally, debuggers have been designed to work in the context of a single thread at a time. In order to work with a different thread, you needed to first switch the thread context. Visual Studio 2012 has a feature known as Parallel Watch window that allows you to display the values of a variable or expression on multiple threads.

In this recipe, we are going to see how to view the value of a variable across multiple threads using the Parallel Watch window.

How to do it…

Let's see how the Parallel Watch window can help us view variable values across multiple threads.

  1. In Visual Studio 2012, press F5 to run the project.
  2. When the debugger hits the Debug.Break statement, go to the Debug menu of Visual Studio 2012, and click on Windows. Then click on Parallel Watch and Parallel Watch 1 to view the window.
  3. By default, the Parallel Watch window brings up all the threads currently executing in the process. In order to add new watches, we need to click on <Add Watch> column which allows us to enter an expression. Click on <Add Watch> and enter numbers as the expression to watch. As soon as the watch is added we can now see the expression evaluated across all the different threads in the Watch window.
    How to do it…
  4. Enter a Boolean expression in the Filter by Boolean Expression box. The debugger evaluates the expression for each thread context. Only rows where the value is true are displayed.
    How to do it…
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.71.72