locked
Do Static variables defined in Global.asax ever expire? RRS feed

  • Question

  • User-2053865247 posted

     In my default.aspx.cs Page_Load, do I ever have to worry that the following statement will throw a null reference exception? (Please also see global.asax.cs at the bottom of this post)

    if (Global.Debug) 
    {
    // do something 
    }

    In other words, do static variables that are defined in the Global class ever "expire"?  My assumption is "No" but I'm curious to hear what you think.  Thanks, Matt

     

        public class Global : System.Web.HttpApplication
        {
            public static bool Debug = false;
            
            void Application_Start(object sender, EventArgs e)
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    Debug = true;
                }
            }
        }

     

    Tuesday, November 29, 2011 7:43 AM

Answers

  • User1049502825 posted

    no...it will not expire.....untill iisreset.....

    if IIS on server will restart then again value assign to Debug that parameter...

    MARK AS ANSWER IF THIS WORKS....

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 29, 2011 7:58 AM

All replies

  • User1049502825 posted

    no...it will not expire.....untill iisreset.....

    if IIS on server will restart then again value assign to Debug that parameter...

    MARK AS ANSWER IF THIS WORKS....

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 29, 2011 7:58 AM
  • User-519136805 posted

    It expire in the following conditions :

    1) IIS Restart

    2) Application Pool Reset

    3) Memory outage

    This conditions applied only if you are using "InProc" , if you are using 'OutProc" session state than this will not apply.

    Hope this will helps !!!

    Wednesday, November 30, 2011 7:45 AM