I am writing a program recording service calls and treatment done. We have a number of users who open and close calls and I want to show at all times the total number of calls opened today and the total number closed today and the difference between them. I thought of doing it with an application variable. I have to reset these variables to 0 every day. Where would I do that? I thought in the Global.asax but in which event could that be done? The application is running all the time so I suppose Application_Start wouldn't be appropriate. So where? Thank you.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
You could configure the Periodic Restart Settings for Application Pool Recycling in IIS:
But this has a side-effect of putting the application offline during the time the pool is restarting, so if you have any user connected at that time it will lose its session. This can be minimized by restarting the application at a time you have no users connected, like at dawn.
The following config snippet set the application pool to daily recycle at 3:00 A.M.:
I'd have a date variable with the last time the counter was reset, and check the date is "today" on every access to the counter.
Unless you have critical performance problems, I guess that'd be the way to go.
Sample easy-lazy code to call whenever you are updating the counter:
Now we'd need to know more about how you'd like to be storing those variables (
myCounter
andlastDateCounterWasReset
), but could be basically anywhere (database, filesystem, etc.)I suppose you could use the
Application_BeginRequest
method. Use a boolean to see if it's already run that day.Another option is a scheduler with a hidden URL to reset.
I would store the calls to a database and do a select which groups by the current day to get the total calls, etc. for display.
That way it will automatically reset for you when a new day starts, and you don't need to worry about IIS Resets destroying your in memory data.
If you don't want the performance hit of querying too often, there are a number of caching options available.