Setting Watches in Code

A watch enables you to track the changes in the value of a variable or expression during program execution. The Watches window opens at the bottom of the editor and lists all of the watches you have defined for your project. You can create a watch directly from the Source Editor or with the Debug > New Watch menu selection.

When you create a watch, the value of the variable or expression is immediately evaluated and displayed in the Watches window. The value of the watch is based on the current context. When you change the current context, the Watches window is updated to show the value of the watch for that context. When a debugging session is running, you can use code completion in the New Watch dialog box.

To create a watch:

  1. Select the variable or expression in the Source Editor.
  2. Either right-click on the selection and choose New Watch or select Debug > New Watch in the IDE menu bar.
  3. The New Watch dialog box opens with the variable or expression entered in the text field.
  4. Click OK.

The Watches window opens at the bottom of the IDE with the new watch selected.