Add Ons - DevSource
DevSource: Microsoft Developer Resource DevSource Home Sponsored by Microsoft Home Add Ons Architecture Languages Techniques Using VS Forums
Home arrow Add Ons arrow Page 3 - Win Command of the Command Line Interface
Win Command of the Command Line Interface
By John Mueller

Rate This Article: Add This Article To:

Win Command of the Command Line Interface - Debugging
( Page 3 of 7 )

Handling Debugging

One of the problems with console applications is that they execute and immediately exit. So, when you try to debug your application, you see a quick flash of the output and that’s it. Of course, you could place a breakpoint into the IDE, but that only helps when debugging from within the IDE. You might want a debug version of your utility to use with a batch file or script. The example application includes a special method called CheckDebug() that appears in Listing 2.

ADVERTISEMENT

Listing 2: Adding a Pause to the Debug Version

      static void CheckDebug()
      {
#if (DEBUG)
         Console.Write("Press any key when ready...");
         Console.ReadLine();
#endif
      }

Visual Studio automatically creates a constant called DEBUG. You can set this constant on the Built tab of your project’s Properties dialog box as shown in Figure 2. The code shown in Listing 2 relies on the DEBUG constant. When you create a Debug build, the DEBUG constant is defined and the compiler adds the pause code into your application. When you create a Release build, the compiler doesn’t add the code, so the command line application works as normal.

Figure 2: The IDE adds both a DEBUG and TRACE define to your application by default.



 
 
>>> More Add Ons Articles          >>> More By John Mueller
 



HD VOIP Has Arrived (with Tony Konstner)

Play Video >

All Videos >

Google and blonde jokes?

Read now >

Favorite books!

Read now >

View Now
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.