65.9K
CodeProject is changing. Read more.
Home

How to Debug Windows Services and Plugins

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Jun 24, 2010

CPOL
viewsIcon

13202

How to Programatically (and configurably) Launch a Debugger

If you’ve ever had to create an component hosted inside a third party application (such as a plugin or Windows service), you’ll know that it can be pretty tricky to get the debugger attached to the process quickly and reliably. Here’s a snippet that I’ve taken from project to project:
#if DEBUG
            if (Properties.Settings.Default.LaunchDebugger
                && !System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Launch();
#endif
This statement checks to see if launching the debugger is allowed (using the standard settings classes) and launches the debugger if one isn’t already attached. For release builds, the entire line is removed from code to avoid ‘accidental’ debugging.