Answered by:
Advice Needed On Timer Architecture

Question
-
User-817646753 posted
i am developing an asp.net web app. i need to kick off a separate thread every monday morning. ive put an instance of System.Threading.Timer in the Global.asax file to handle this.
im concerned that i might be walking into a WOH (World Of Hurt) by using this methodology. im not sure if putting a Timer in Global.asax is a sound solution for an asp.net web app.
i'd be grateful for any advice on this as the timed function is critical to my web app so i need to get this right.
thanks.
Friday, January 12, 2007 9:58 PM
Answers
-
User300685930 posted
I'm not sure global.asax is going to be the best place to put it. the problem is that each time the server resets (which can happen without you knowing it), so does your global.asax.
If possible, you are really much better off trying to create a standard service on your windows server operating system and put the timer there.
Good luck with this.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, January 12, 2007 10:03 PM
All replies
-
User300685930 posted
I'm not sure global.asax is going to be the best place to put it. the problem is that each time the server resets (which can happen without you knowing it), so does your global.asax.
If possible, you are really much better off trying to create a standard service on your windows server operating system and put the timer there.
Good luck with this.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, January 12, 2007 10:03 PM -
User-817646753 posted
hi peter
unfortunately i am at the mercy of a third party web host so best for me to avoid the service route, although i agree this would be better in an ideal world.
when the server resets, im figuring that my Application_Start event will get fired again afterwards, so i can restart my timer in there.
in case the server reset whilst my timer routines were in progress, i could put in event logging for this so that i would know if i previous routine needed recommencing.
does this sound like a sensible workaround to you? or could you think of a better way?
thanks
Friday, January 12, 2007 10:20 PM -
User300685930 posted
I understand why you need to go this route. Just like you, it makes me nervous. I guess if it were not mission critical, you solution sounds like it should work. I've been stung many times by server restarts.
Maybe you could somehow have a flag set when your process finishes. Then, every so often (like every hour) check if it has been 24 hours since the last server has run. You could even do that check from your application timer which you start in application_start. Still makes me nervous.
Friday, January 12, 2007 10:40 PM -
User-817646753 posted
another option im considering is using the data cache and the cacheitemexpiry delegate to trigger my method.
i think this would work as a substitute to the timer method.
perhaps you may have a comment on this idea?
otherwise ill just plod on and hope for teh best :)
Friday, January 12, 2007 10:49 PM -
User-817646753 posted
im thinking i could also write the service for my local computer, then get this to trigger the asp.net method via a web service. but this means my computer needs to be on every monday morning.
oh well...it was worth a thought... :)
Friday, January 12, 2007 10:51 PM -
User300685930 posted
I'd stay away from Cache. too much memory pressure. I like the web service idea if you can pull that off.Friday, January 12, 2007 11:10 PM -
User-389939489 posted
Hello guys, there is a very simple approach to this: start a System.Timers.Timer from Application_OnStart, so that if the app recycles, the timer gets correctly restarted.
The timer in question is probably better wrapped into a self standing class dedicated to it, but it might even be a private static member of the Global class.
Btw, I have used this technique extensively and just can tell it works like a charm.
Hope this helps. -LV
Saturday, January 13, 2007 2:04 AM -
User-817646753 posted
hi there. thanks for your reply.
but what happens if the app recycles whilst the TimerCallback method is in progress? do you cater for this in your code?
thanks.
Saturday, January 13, 2007 2:41 AM -
User-389939489 posted
but what happens if the app recycles whilst the TimerCallback method is in progress? do you cater for this in your code?Simply, that shouldn't happen. Unless in extreme cases like a power down or similar, you here should expect a disciplined shutdown of resources, with all dispose-finalize called, and so on. In particular, you should expect the Application_OnEnd to fire, and there I would cleanup. That said, maybe there is some exception you might trap from the working thread about the thread aborting?
Sorry, I have never needed this, and I am not able to go into more details.
Hope this can give hints anyway. -LV
Saturday, January 13, 2007 3:29 AM -
User-1583677305 posted
I would not solve this problem in side of ASP.NET. For task which must run periodically at specified time I would create separate system service and install it into operating system independently of ASP.NET solution.Saturday, January 13, 2007 5:30 AM -
User1085080990 posted
Hello, everyone.
U dont need timer at all. This is common problem, so just check ntp.isc.org for info about NTP (Network Time Protocol) Public Services.
Also, there are a bunch of free (broadcasting) time web services (google helps).
So, just write some kind of biz logic rule inside your app to check (listen to time web service or NTP server) to do smth at (or after) concrete time in full format (time+date).
Best regards.
Saturday, January 13, 2007 7:25 AM -
User84020908 posted
HI
I want to use to call my web service at every 1 minute
can i use ntp to make this task work . or is there any way which is efficient to call my webservice
thanx in advance
From
Mukeshv
Friday, February 9, 2007 9:05 AM