views:

163

answers:

4

Hello.

In Visual Studio (2005/2008) we can set a conditional breackpoint when the condition is True. Now, there is an other option - when is "Changed".

What does this mean and how/when should I use it.

I saw already related page on MSDN but this "changed" it still not clear for me...

Thanks.

+1  A: 

It means that every time the value of the expression changes the breakpoint will activate.

The use case is when you want a breakpoint to be hit but only if something interesting has changed in the code. In a loop, for example, you might want to break only when some value has been incremented and not on every iteration of the loop.

Martin Peck
A: 

Has Changed does not get evaluated on the first run. It breaks when the evaluation of the expression for the breakpoint has changed.

Jacob R
Wrong. It just hooks the memory - no evaluation involved.
alemjerus
A: 

This "changed" conditional breakpoint applies only to several bytes of memory (1, 2, 4 or 8), whose address and count you specify in the breakpoint settings. When, during the program execution, something changes these bytes, the program execution breaks at the point where the change was made. Usually it is used for debugging cases of unintentional memory/variable changes when you don't know who and how exactly changes your stuff.

alemjerus
+2  A: 

Best explained with an example:

  for (int ix = 0; ix < 10; ++ix) {
    Console.WriteLine(ix);  // Break here
  }

Type an expression in the breakpoint dialog that evaluates to a simple bool or integral value. For example: "ix / 2". When you run it, execution will break on the first pass through the loop and only whenever ix is an even value.

This is not a data breakpoint btw, alluded to in another post. Those are not supported in managed code. The debugger actually breaks program execution temporarily and evaluates the expression every time. Only to stop execution when the expression value has changed. This can make your code run a lot slower as a side-effect.

Hans Passant
"bool or integral value" if I have in the expression a complex class, let's say a (winforms) button *btn* and I will change the *btn.Text* will the breackpoint break? Or if I have a *myString* changing from "test" to "text" will be this considered like a "change"?
serhio
There's no code that you can set the breakpoint on. Implement the TextChanged event.
Hans Passant