When a program is running under the control of the debugger in the Delphi IDE, it is possible to detect this because the variable "DebugHook" is set to a value <> 0.
Is there an equally easy way to check for the debugger when debugging a .NET program in Visual Studio?
To achieve the same in .NET reference "System.Diagnostics" and add this code