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.
I'm a lead developer for Freestyle Interactive Ltd where we create many wonderful websites built on Microsofts ASP.Net and Ektron CMS.
I've been developing .Net applications (both Windows and Web) since 2002.