Conditional breakpoints in Visual Studio

It’s a small but very powerful tip, especially helpful when you are debugging large code base. This is the concept of Conditional Breakpoints.

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.

Conditional breakpoints

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‘.

Conditional breakpoints

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.

Conditional breakpoints

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

Conditional breakpoints

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

Conditional breakpoints

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


About Jasminder

.Net developer and blogger by profession, keen to learn new technologies, love nature, music and cricket.
This entry was posted in Tips & Tricks and tagged . Bookmark the permalink.

I have a suggestion..

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s