Q:

Testing if code executes in debug mode

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

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

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

