Saturday, July 4, 2015

Conditional Breakpoints in Visual Studio

This is just a simple trick which many of you might have been using. It's a small but very powerful tip, especially helpful when you are debugging large code base. This is the concept of Breakpoint Conditions.
As the name itself suggests, it is setting the breakpoints which are hit, only when certain condition is met. It's easy to implement as well. Create a new application and set a normal breakpoint.



So this will be hit every-time the Page_Load executes. This could be very annoying when you are debugging for a bug and this keeps on hitting this breakpoint. So let's make it conditional. Simply put your mouse on the breakpoint, right click and select 'Condition'.




This will open up a window where we can define a condition to hit the breakpoint only when the condition is met. Even you get the intellisense help for it.



See how the color of the breakpoint changes with a plus sign on it. Also, hover over it and you can see the details.




Now let's run the application. First time, no breakpoint is hit. Press the button for postback and see the breakpoint gets executed.




Even you can set this condition to be on your variables or properties etc.  So happy debugging now...!!!

No comments:

Post a Comment