static variables not persisting RRS feed

  • Question

  • User1135050801 posted

    Our ASP.Net application is such that it relies on a couple of static C# variables, that is, data that is supposed to be persistent for the life of the application.  Using an external program, we are generating HTTP requests and for the most part, that static data is persisting.  However, after approximately 28 hours, that data is lost and the variables are re-instantiated.  Our best guess is that ASP.Net is “cycling” for some reason.

    After some research, we see that there is a section in the machine.config file, named <processModel> and that it can contain an attribute, timeout, that’s supposed to specify how often ASP.Net should be cycled.  The attribute is actually not present in our configuration and our understanding is that its default is “infinite”.

    Perhaps ASP.Net is being cycled due to something else…  In order to try and understand the timeout setting, we set it to something very small, like 3, and we do not see the expected effect – that is, we expected to see ASP.Net cycle after 3 minutes and do not.  Though this isn't the problem we're trying to solve, it is interesting...

    The application is hosted on a Server 2008 R2 (x64) server.  The machine has several versions of Dot-Net installed on it, but the application’s app pool is configured for version 2.0.

    Any thoughts?  Why is our static data reinstantiating?


    Tuesday, May 14, 2013 9:27 AM


  • User-183374066 posted

    1. If static variable declares in any class than it would be reset on every new instance of class

    2. Statis variables are related to App Domain recycling. When it recycled all the sessions and static variables are reset. So you better set IIS settings for the app domain and set values that is suitable to your requirement.

    3. The static variables are lost if the system restarts or IIS reset.

    Read more on it

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 14, 2013 9:43 AM