vb.net Add Watch stop when value changes

2019-02-16 15:39发布

问题:

I know in the older versions of Visual Studio, there was an "Add Watch" option where you can choose to stop execution when the value of the field changed. I am using VS 2010, and I can't figure out how to hit the breakpoint when the value of the field changes.

Any ideas?

回答1:

Data breakpoints is what I remember, your description matches. It used a processor feature, it requires the address of the variable and the size, the processor automatically generates a trap when it detects a write to the memory address. Very nice debugging tool.

Sadly no longer available in managed code, the garbage collector messes it up because it moves objects around while compacting the heap. Which changes their address. The interface between the garbage collector and the debugger isn't strong enough to allow the debugger to track these moves while the compacting is taking place at runtime. No doubt to avoid a serious amount of overhead.

The next best thing you got is a property setter. You can set a breakpoint on it.



回答2:

Right click on the breakpoint and hit Condition. You should be able to do the same from here.



回答3:

You can right click on a break point and then choose Condition. In the condition box type the name of the variable and select the 'Has Changed' radio button.



回答4:

In vb.net 2010 (I am using the express edition) - set a breakpoint and run up to it. Right click the variable/control name you wish to watch then select add watch from the context menu.

The watch window will appear.

You can type variable names directly in to the watch window, providing they are in scope.