Application Variable Resets

Discussion in 'ASP.NET / ASP.NET Core' started by ako_akoto, Jun 7, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I try to make a hit counter for my site. I did this by maintaning an application variable that is continuosly incremented whenever a new session is made. but after several hours, i noticed that the application variable that contains the hit count is reset to its intial value (1). I think one reason for this is that the web application is being restarted?But why?..or is there any other reason for this?..pls help.
     
  2. You shouldn't store the counter data in Application. The application processes do get restarted after a certain idle time. You should store it in a database.

    Aristotle

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. I see. But can i store the counter value in the database on application close?..or whatever event is triggered when you restart the application?..What event can i handle so that when that event is triggered, i store the application variable in the database.
     
  4. Application_End is not reliable. It will work most of the time, but never 100%.


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  5. what event can i handle then?
     
  6. also, why is application_end not reliable?
     
  7. It's not reliable to store data because there are times when it will not fire. reboot, recycle iis, application crash, process hang, etc.

    If you're looking for an Application_End like event to handle the Application_End like stuff, there isn't one. Application_End is the only one.


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  8. the application variable was reset several times today and yesterday..does that mean that your server reboot, or crashed, or hang several times today and yesterday?
     
  9. whats the use of application variables then?
     
  10. Lets say you pull data from a database and store it in a System.Data.DataTable object. but this data never changes. You could store that in the Application state and query that data instead of making a round trip to the server.

    Many people have tried to make counters that are stored in Application or Session, but they are always unreliable.

    Your process could have been recycled due to inactivity (like session timeout). This is a completely normal process.

    There are too many reasons why Application_End will not fire or application will be recycled, I don't even know them all.


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  11. 'Lets say you pull data from a database and store it in a System.Data.DataTable object. but this data never changes. You could store that in the Application state and query that data instead of making a round trip to the server.'

    That sounds nice a solution. But if we still store the DataTable in the Application state, whats the difference with the current solution. What if you maintain the hit count by a DataTable and you store the DataTable in Application state, then suddenly the application was restarted for some reason and the application_end was not triggered, when do you update the server?, what happens? Same problem right? ...Is the Application_End triggered most of the time?like 90%?
     
  12. Oh i see..pardon me for that..i know what application variables are and what they are for...i meant to ask, whats the use of application vairables if the application is refreshed or restarted or recycled without an event being triggered, that will give you the time to do something to them before thay get lost?..if the server shuts down or crashes, i understand most likely the application_end will not be triggered, you lose application variables and you cant do anything aBout it...application recycle seems to be a normal thing, but shouldnt the application_end be triggered everytime it happens?..because i think the only time application_end will not be triggered is when somethign unexpected or abnormal happened...i just wanted to know how often the application restarts without application_end being triggered... Anyway, il just experiment, il try to make a log to see if application_end is triggered when the application recycles. Thank you so much for your replies, i really appreciate it..Please inform me or correct me if i what i said above are wrong..Thanks again :)
     
  13. no one really knows how often or all the causes that would make the Applicaion_End not fire.


    People are just aware that it will not fire 100% of the time (this goes for Session_End as well). Even if it fire 99.999% of the time, you data will be wrong... how wrong? who knows.


    Because it is not 100% it's not considered good practice to use it to cache data that should be written to a database or the hard drive.


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  14. Joel wasnt giving you a solution, he was responding to your question "whats the use of application variables then?"

    His explanation is a good one. It can eliminate DB round trips. But that data can be "purged" at any time when the app gets recycled, so using it to store cumulative data is not a good idea. It is better suited for static data, as Joel suggested
     
  15. thats right...il just go straight to the database...thanks a lot for your replies :)
     
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