SIGN UP MEMBER LOGIN:    
ARTICLE

Debugging Tips using Visual Studio

Posted by Suchit Khanna Articles | Visual Studio 2010 June 02, 2011
I will share some debugging tips which many of you might be knowing already but this is for who not know the full capabilities of the Visual Studio
Reader Level:
Download Files:
 

Hi folks, today I will share some debugging tips which many of you might be knowing already but this is for who not know the full capabilities of the Visual Studio Editor and are missing out these features while doing their development activities.

Many a times while writing/analysing code we come across scenarios where one wants to break a certain piece of code when certain condition is met, one of the methods that comes first is to put a break point and wait till that condition is met.

Let us see how we can achieve conditional debugging in Visual Studio:

I have taken simple console based application and written a small piece of code that simulates a long for loop:

for (int i = 0; i < 20; i++)
{
    Console.WriteLine("i : {0} ", i);
}
 
Console.Read();



Now put a debug point at line that reads Console.Writeline(), and right click the debug point as shown below in the image:

Debugging1.gif

As you can see there are many options at her hand to play round with, but let us take the simplest of the way around and choose the "Condition…" option and you will get the following pop-up window:

Debugging2.gif

Next we can go ahead and specify the condition for the debug point to hit in the textbox available (one of the cool things is that you will get the intelisense feature here too and you can access all the variables defined in the scope:

Debugging3.gif

As you can see I can access my local variable which I defined earlier in our code sample, going ahead let us specify that the debug point hits only when the value of i is equal to 6.

Debugging4.gif

After we are done with condition specification, press ok and you will see a white mark on debug point which specifies that the debug is a not a normal debug point but comes with some condition specified over it.
Now run you solution by pressing F5, and you will that the debug point is hit only when I becomes 6 in the loop.

Debugging5.gif

You can verify the same in the Locals window the value of the variable. This is indeed a valuable feature to have a big set of values to debug out with a specific value.

We will continue our journey more on the same, till then have fun.

Cheers, 

Login to add your contents and source code to this article
share this article :
post comment
 

Thanks Latha.

Posted by Suchit Khanna Jun 08, 2011

Very Useful. Thanks

Posted by Latha Jun 08, 2011

Thanks DJ :)

Posted by Suchit Khanna Jun 02, 2011

Thanks for sharing. Nice article

Posted by Dhananjay Kumar Jun 02, 2011
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor