Skip to Main Content
Professional Visual Studio® 2008
book

Professional Visual Studio® 2008

by Nick Randolph, David Gardner
July 2008
Intermediate to advanced content levelIntermediate to advanced
1026 pages
27h 59m
English
Wrox
Content preview from Professional Visual Studio® 2008

45.2. Debugging with Code

Three classes ship with the .NET Framework under the System.Diagnostics namespace that can be used to build debugging support directly into your code — the Debug, Debugger, and Trace classes. When used properly, these classes provide a very powerful way for you to interact with the debugger.

The functionality provided by all three of these classes is exposed through static/shared methods and properties, which makes it easy to add them to your code.

45.2.1. The Debugger Class

The Debugger class provides programmatic access to certain debugger functions within Visual Studio. For example, the following code snippet will check whether the application is running under a debugger and, if not, launch one and attach to the process:

if (!Debugger.IsAttached)
{
    Debugger.Launch();
}

When this code is executed while the application is running normally outside Visual Studio, the program execution will pause, and you will be presented with a dialog box similar to the one shown in Figure 45-3. Selecting "New instance of Visual Studio 2008" will load the application in Visual Studio and continue executing the application in debug mode.

Figure 45.3. Figure 45-3

45.2.2. The Debug and Trace Classes

The Debug and Trace classes are used to output debugging information and trace the execution path of your application. Most of the properties and methods are common across ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Professional Visual Studio® 2010

Professional Visual Studio® 2010

Nick Randolph, David Gardner, Michael Minutillo, Chris Anderson

Publisher Resources

ISBN: 9780470229880Purchase book