Static variables

Discussion in 'ASP.NET / ASP.NET Core' started by Marching, Apr 7, 2012.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I understand that applications are dropped after 20 minutes of inactivity.

    When the next request comes in, shouldn't application_start be executed again?

    In my application some static variables are initialized in application_start.

    After the period of inactivity, when I access pages that depend on the static vars, they are null and that creates errors.

    Since these variables are initialized in application_start, it seems odd that after the period of inactivity that they would be null since the application restarting should reinitialize them.

    In fact, when I see the null reference errors, recycling the app pool (and executing application_start) solves the problem until the next time the application is dropped from memory.

    I'm wondering if some other type of system memory problem is occurring when the application is removed from memory, because if the application was simply being recycled, the reinitialization of the static variable in application_start would mean there would be no reason for the statics to be null.

    Since static variables are not garbage collected they should never be null after initialization.

    These static variables are initialized in application_start.

    There is something that the system is doing after the period of inactivity that is abnormal, not simply recycling the application.
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    application_start should always be executed when a worker process starts.

    Are you sure if the site appPool was shutdown due to inactivity? or could it be something else??
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page