views:

57

answers:

4

In Visual Studio 2008, I am using C# if that matters, how do I set a watch on a property so I see whenever the value changes during execution?

A: 

You need to enter debug mode, so if you're running an application, run in debug. Otherwise, if you're running a web service, you need to attach to the process (like aspnet_wp.exe).

Then, you should have a watch window in the bottom of visual studio, where you can see the value of the property. (you get the property in this window by either typing the name in one of the spaces, or by clicking add to watch for the variable)

The last step is to place break points (stopping points) in your program where you want to see the value that you're watching.

Brett
+1  A: 

In debug mode set a breakpoint, right click on the property you want to analyze and click "Add watch". The value will be shown in Watch window

mamoo
A: 

While you are debugging you can right click on any variable and choose add watch. Also you can pull up the watch window and manually type it in the name column. I usually set a breakpoint at the start of my program so I can add watches, also they should be there the next time you debug project so you don't have to do it each time.

+1  A: 

If you have set a breakpoint, then you can right-click on the "breakpoint dot" and select "Condition". Here you can specify that the breakpoint is only hit when some value (you need to type in the variable name) changes.

A "watched" value will show in red when the value changes.

Hans Kesting
This caused a "watch" window to appear. Then I could turn off the breakpoint. Also the option to add to watch appeared when right clicking any other variable. How could I get a watch window to appear from the toolbar to start off with?
Lill Lansey
The watch window appears when you enter debug mode/attach to process
Brett