Conditional Breakpoints in Visual Studio 2010

So this is something I’ve known about ever since I started doing ASP.NET development, and I’m sure that many developers know about this, but I thought I’d share this for those that don’t, because it’s such a cool feature.


So you’ve got a method that you want to debug for some reason, but let’s say this method gets called quite often and you’re only really interested in debugging the method when a certain parameter contains a certain value.  Happens more often than you might think.  You could throw a breakpoint at the first line of code, but then you have to hit F5 to continue normal processing until you get the specific condition you want to debug.  Or, you can give your breakpoint a condition.  Here’s a quick screen-grab:



Basically, all you have to do is right-click on your breakpoint to get this menu.  There are, as you can see, several options you can set for your breakpoint, some more advanced than others.  The one we’re going to look at in this blog post is the “Condition…” option.  Clicking this option will give you the following window:



Now, “fieldName” is one of the arguments to the method that I’m debugging, and as you can see, I’m only interested in hitting this breakpoint if the value of that argument is “SaleStartDate” or “SaleEndDate”.  If the “fieldName” argument does not equal either of those strings, code does not break on that point and continues on its merry way.  This way, I only get a code break when I want it.


Again, this is probably nothing new for most of you out there if you’ve been doing development with Visual Studio for any length of time.  But there was a time that I didn’t know about this, and I’m sure there are others that don’t.


As always, questions/comments/suggestions are welcome in the comments.


~ by interneth3ro on January 17, 2012.

Leave a Reply

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

%d bloggers like this: