Decrease Font Size
Increase Font Size
   BLOG

ASP.NET windows application - detecting debug mode

Today, I was working on one of the windows application and at one point I need to figure out if the application is running on the Debug mode or Release mode.

We can use HttpContext.Current.IsDebuggingEnabled for the web applications.

As for the Windows Application, Initially I was using the code below

 internal static bool DebugMode()
        {
            bool isDebugMode = false;
//Application.StartupPath will give me the path for the executable file that started the application
            if (Application.StartupPath.Contains(@"\bin\Release")) //it will be \bin\Debug if we running on Debug Mode
                isDebugMode = false;

            return isDebugMode;
        }

 

But then I found this piece of code, which I think is cool because I never thought about this approach

 

from http://www.west-wind.com/WebLog/posts/10228.aspx

 

 internal static bool IsDebug
        {
            #if DEBUG
                get{ return true;}
            #else
                get { return false; }
            #endif
        }