How to detect if program execution is in debug mode?

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

If I'm running the executable, I need to do something, but if I am running
the program fom within Visual studio I need to use another bit of code.

Thanks for any help.

Bob
 
Bob said:
If I'm running the executable, I need to do something, but if I am running
the program fom within Visual studio I need to use another bit of code.

Maybe the following solutions fit your requirements:

\\\
#If DEBUG Then
Console.WriteLine("Debug mode.")
#Else
Console.WriteLine("Release mode.")
#End If
///

Make sure that the option "Configuration settings" -> "Build" "Define DEBUG
constant" in the project properties is checked.

- and/or -

You can check if a debugger is attached:
'System.Diagnostics.Debugger.IsAttached'.
 
Thanks

Herfried K. Wagner said:
Maybe the following solutions fit your requirements:

\\\
#If DEBUG Then
Console.WriteLine("Debug mode.")
#Else
Console.WriteLine("Release mode.")
#End If
///

Make sure that the option "Configuration settings" -> "Build" "Define
DEBUG
constant" in the project properties is checked.

- and/or -

You can check if a debugger is attached:
'System.Diagnostics.Debugger.IsAttached'.
 
Bob said:
If I'm running the executable, I need to do something, but if I am running
the program fom within Visual studio I need to use another bit of code.

If System.Diagnostics.Debugger.IsAttached Then
' Debugging
Else
' Running from Executable
End If

HTH,
Phill W.
 
Back
Top