Not registered yet?
Register now! It is easy and done in 1 minute and gives you access to special discounts and much more!
Is there an easy way to set conditional breakpoints in Visual Studio?
If I want to hit a breakpoint only when the value of a variable becomes something, how can I do it?
Create a conditional function breakpoint:
In the Breakpoints window, click New to create a new breakpoint.
On the Function tab, type Reverse for Function. Type 1 for Line, type 1 for Character, and then set Language to Basic.
Click Condition and make sure that the Condition checkbox is selected. Type instr.length > 0 for Condition, make sure that the is true option is selected, and then click OK.
instr.length > 0
In the New Breakpoint dialog box, click OK.
On the Debug menu, click Start.
Writing the actual condition can be the tricky part, so I tend to
Advantages of using the Immediate window:
This example breaks when the code is referring to a table with the name "Setting":
Visual Studio provides lots of options for conditional breakpoints:
To set any of these you
These options are as follows:
foo == 8
On Visual Studio 6.0
-1) This doesn't work in VS 2012 2) This question already has plenty of other (better) answers and 3) who on earth cares about VS 6.0 (released in 1998)? 4) Even if someone cares about VS 6, the question is tagged with .Net which didn't have support until the next version of VS (Visual Studio .Net)
Well, the other answers do not work on VS 6.0. So I posted a solution.
Just another way of doing it, (or if you are using express) add the condition in code:
Create a breakpoint as you normally would, right click the red dot and select "condition".
When you are using Express edition you can try this:
if( fooVariable == true )
if statement makes sure that in release build breakepoint will not be present.
This has a great performance/time-saving advantage. I was iterating through every potential int 'id' in a program of mine (only about 3.5 million), which only takes a couple of seconds. I was trying to use the conditional breakpoint but since it wasn't in a conditional branch it slowed down the execution speed to the point where after a few minutes I would just terminate the debug session. Using the compiled breakpoint made it instantaneous.
Set the breakpoint as you do normally, right click the break point and select condion option and sets your condition.
The breakpoint will only get hit when i is 5.
Set a breakpoint as usual. Right click it. Click Condition.
In VS 2015 you need to hover over the breakpoint and click the gear icon to set conditions
You mean, right click, set condition, get "Condition for a breakpoint failed" error.. didn't you?
Answer should also include syntax for conditional statements, or an informative link.