Set a Complex Breakpoint Condition

Menu:  [Right-Click the Breakpoint] -> Condition
Versions:  2008,2010
Published:  5/4/2010
Code:  vstipDebug0022

 

image

 

So, it turns out that the REAL power of the Breakpoint Condition dialog is the ability to execute any line of code from it.  You could do something really evil like reset a variable so you have an infinite loop:

image

 

 

Or you can use it to call external methods.  This next example illustrates this but, bear in mind, it's an extremely contrived one just to show how this stuff works.  Here is the code we want to execute:

image

 

Notice there is a variable, "x", that is given a value.  In this case, I hard-coded a value but the value would presumably come as the result of some method execution.  I want the breakpoint to only stop if the value of "x" is 20.  I have a method that returns a Boolean value in order to test for the condition I want:

image

 

I won't get into the obvious debate about whether this is a good idea or not and how the method should be constructed or if the average rainfall in the Amazon Basin is a factor here.  I'll just call the method from the Breakpoint Condition dialog.  Notice I use CTRL + SPACE to get IntelliSense here if needed and leverage the new Pascal Case feature by typing "CV" to get "CheckForValue":

image

 

Make sure the "Is true" option is selected:

image

 

And, if I put my mouse over the glyph, I can see the condition in the Tooltip:

image

 

Now I have a conditional Breakpoint that uses an external method to determine if the code should stop or not.  Naturally, you can add more Boolean logic here as well and include And / Or / Not / Xor:

image

 

Now the really cool part is you can have your checking code only be around for your Debug builds:

image

 

By surrounding your code with Conditional Compilation Directives you can easily have checking code that is only around for debugging.  Here is what the checking method would look like:

image

 

Play with this feature some and you will see why most people (including me) think that this is the most powerful Breakpoint feature there is.