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:
&& !System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Launch();
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.