Way to tell if in debug mode

  • Thread starter Thread starter Marty
  • Start date Start date
M

Marty

Is there a property or method to tell you if you are running in the IDE
or as a compiled exe? Thanks.
 
Do a check against System.Diagnostics.Debugger.IsAttached.
If it's true than a debugger is attached, otherwise not.
 
You can tell in wich configuration your code is compiled by compiler
directives:

#if DEBUG
//Add code here
#else
//add code here
#endif

you can set the soulution configuration (DEBUG/RELEASE) in the Project
Property Pages, Configuration Manager.

This is not exactly an answer to your question. The executed code is the
same as compiled .exe and in the IDE. But you can make a difference to your
debug version and release version.

I hope this helps
 
The System.Diagnostics.Debugger.IsAttached property will indicate whether a
debugger is attached to your process. However, the VStudio IDE is not the
the only possible debugger. Are you perhaps more interested in whether your
component is being used in design mode within the IDE?
 
If this is a Windows Forms component, you can use the DesignMode property of
any type that inherits from System.ComponentModel.Component (which most
controls and forms do). For an ASP.NET control, you should instead check if
there is an HttpContext. i.e.: <in design mode> = (HttpContext.Current ==
null).

HTH,
Nicole
 
Hello

Our approach (windows forms app):

public static bool IsDesignMode()
{
return (Application.ExecutablePath.ToLower().IndexOf("devenv.exe")
!= -1) ;
}

When you have executable name you can do it in a similar way.

Aleksandar
 
Back
Top