.NET equivalent to Delphi's "DebugHook" variable to test for presence of debugger

200 Views Asked by At

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?

1

There are 1 best solutions below

3
Olaf Hess On

To achieve the same in .NET reference "System.Diagnostics" and add this code

if (System.Diagnostics.Debugger.IsAttached) then
   // Program is running under the control of the debugger