BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Debugging
VS2003+

Visual Studio QuickWatch

The QuickWatch dialog box is one of the large number of debugging windows and tools provided by Microsoft Visual Studio. QuickWatch allows ad-hoc expressions to be evaluated and variable values and properties to be browsed without adding a watch.

Watches

In an earlier article I described the use of the watch windows and the locals and autos windows, each of which permits you to view the current values of variables, their properties and fields, monitor those values as you debug and edit the values where applicable. The watches windows extend the functionality by letting you add expressions to the items being monitored, with the results being recalculated automatically as underlying variable values change.

This QuickWatch dialog box can be thought of as a simplified version of the watches windows, presented as a dialog box. It allows you to concentrate on a single variable or expression at one time, browsing fields and properties and editing values in the same way as with other debugging windows. QuickWatch is not used to monitor variables, as the dialog box is modal and therefore prevents you from stepping through your code whilst it is visible. It provides an immediate evaluation of a variable or expression only.

Showing the QuickWatch Dialog Box

To view the QuickWatch dialog box whilst debugging your code you can highlight the variable or expression that you wish to interrogate, right-click it and choose "QuickWatch..." from the context-sensitive menu. You can also choose "QuickWatch..." from the Debug menu. The dialog box will open with the selected item already available for viewing.

Visual Studio QuickWatch dialog box

In the above dialog box you can see that the testVector variable has been examined. The grid in the centre of the dialog box is similar to that of the watches windows. You can resize the columns and browse or edit the values as you might expect. The item being interrogated is shown in the Expression combo box. You can edit this expression and click the Reevaluate button in order to show the details of another item. You can also use the drop-down arrow of the combo box to choose from previous QuickWatch expressions.

If you decide that you would like to save the expression so that you can monitor it further, you can convert it to a watch by clicking the Add Watch button. A new watch containing the current expression is added to the Watches 1 window, which will be displayed if it is currently hidden.

Watch or QuickWatch?

Visual Studio provides many debugging tools with overlapping functionality. The QuickWatch dialog box and the Watches windows are a good example. You may decide to use one or the other exclusively or a mixture of the two according to your immediate requirement. The QuickWatch window tends to be most useful when you wish to quickly examine a variable's properties. As the dialog box can be resized you can enlarge it to show lots of information at once.

3 August 2011