Use Conditional Breakpoints with Method Calling in Visual Studio

Use Conditional Breakpoints with Method Calling in Visual Studio

Visual Studio Breakpoints allow you to put conditional breakpoint. If and only if that condition is satisfied, the debugger will pause the execution. Along with the normal condition with in conditional breakpoint in visual studio, we can call a methods from the condition field and based on the return value debugger will stop at the breakpoint.

Let’s say you have a method with return type bool and you one of your breakpoint will only hit if IsValidData returns false.


 private bool IsValidData()
 {
 bool retsult = true; 
// Do Some operation
 // result value may change based on the operation
 return result;
 } 

Now, you have to set the conditional breakpoint as shown in below,

image

Now, if the result=true the breakpoint will never hit, breakpoint will only hit if IsValidData = false.

Similarly not only for Boolean type, you can use the same for any type of return value. As shown in below image, we can set conditional breakpoint based on some string value as well.

image

You, may think typing condition inside condition text box will be a difficult task, but don’t worry, you can use intellisense with in conditional textbox as well.

image


Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

2 Comments to “Use Conditional Breakpoints with Method Calling in Visual Studio”

Comments are closed.