.Net Debugging – Conditional Break Points

Often developers need to setup breakpoints for debugging. There are times we need to stop execution under certain condition. I used to add logic in my code using following logic

if (i == 1)


    //break here

    i= i;


This works well for debugging, however, it’s a pain to keep my code clean. And, sometimes I forget to clean them!

A few years back, I learned Visual Studio had build-in functions for this type of situation call conditional breakpoints. I have showed to a few coworkers how to use it and now I want to blog it for whoever might see it. It’s a very simple technique yet power in debugging.

Below, I’m showing this in VS2008:

To start, make sure Breakpoint window is open in Visual Studio, if not, press Ctrl. D,B to open it.

In source code, press F9 to setup break point at the line. This break point will show in ‘Breakpoints’ window, right click on this breakpoint, there will be a pop-up menu like this:

Select ‘Condition’, conditional break point setup window will appear. All we need to do is to enter the condition

After setup is done, run the code and it will break when condition is met: 

That’s all.

There is another way to break: hit count, you can enter a number and Visual Studio will stop code when this line of code has been hit for xx many times:

 See how easy it is?

Breakpoint doesn’t change much in Visual Studio 2010:

VS2012 just came out, I haven’t got chance to check it out. Will update once I get chance.


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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