views:

390

answers:

3

How can i test that the code executes in debug mode.

Here is what i would like to do in pseudocode

if not debugMode then
  Do something()
end if
+3  A: 

You can use Debugger.IsAttached to determine whether the program is being debugged.

If Not Debugger.IsAttached Then
  DoSomething()
End If

EDIT If you always want to skip the DoSomething code in the debug build, whether or not a debugger is being used, use conditional compilation with #If, something like this

#IF DEBUG Then
  DoSomething()
#End If
MarkJ
+2  A: 

What do you mean with debug mode? If you refer to a debug build, you can use #if DEBUG to test for that:

#if DEBUG
    // this is included in a debug build
#else
    // this is not included in a debug build
#endif
Fredrik Mörk
A: 

you can use IsDebuggerPresent Function

<DllImport("kernel32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function IsDebuggerPresent() As Boolean
End Function

if not isDebuggerPresent() then
Do something()
end if
Wael Dalloul