Everyone is well aware of various ways of watching value of variable during a debug sessions. Watch, Immediate, Local Variables are just few examples. When working on a multi-threaded application, there may be scenarios that a method is called by different threads which means that a variable may have different values across different threads. If you want to watch the value of that variable across multiple threads, the conventional tools may not be too helpful. This is where Parallel Watch window can come in handy.
Let’s consider the following piece of code. The relevant piece of information here is that CheckIfEven
method is called using TPL AsParallel construct.
The method CheckIfEven
takes an int
variable input as parameter that we want to watch. We can watch its value via traditional Watch window but let’s try to do it by Parallel Watch window. This could be found under one of the Debug menu options as shown below:
Next, we add a watch here. You can do it clicking on the “Add Watch” text and entering the name of the variable.
Now once your break-point is hit, you will be able to see the value of this variable across multiple threads.
Until next, happy debugging!!
Filed under: CodeProject, Debugging