Decrease Font Size
Increase Font Size

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




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