Debugger.IsAttached
The System.Diagnostics.Debugger class provides a handy means of interacting with an attached debugger and to determine whether a debugger is present. The Debugger.IsPresent property can be used to alter program behaviour if you are in a debugging session. After adding unhandled exception processing to an application, the Debugger.IsPresent provides a means of stopping the generation of an application error dialog and just letting the exception through to the debugger when programming. I typically combine an #if DEBUG pre-processor check with a Debugger.IsPresent check so that release mode executables always bring up an application error dialog for "unhandled" exceptions but debug mode executables let the debugger do it's work if it's there.