How to create a timer to do scheduled jobs in web application?

  • Thread starter Thread starter elaine
  • Start date Start date
E

elaine

I have a web appliacation, what i want to do is starting a timer when
"Application_Start" event handler is called. The timer is running
asyncronizely, let's say, every 24 hours, it will create a new thread
to run a certain process, after the process is done, the thread will
be killed.

So far, i have no idea how to do it. Can i instantiate a singleton
object in "Application_Start"? How to make a timer to be running
asyncronizely?

Please help,
Elaine
 
Web applications are not good for this sort of task. Web application
response to client requests and doing something with them outside of client
requests is not what they are for.

Typically, you would either use Windows scheduler or make your own Windows
service.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
What you describe should not be part of the webserver process because it
would be a bad design. You want to trigger a Process X that does something.
So use database triggers, task planer or create an own processes or windows
service that implements the Process X. Encapsulate your logic you wanted to
do in your web application into a assembly and reference it to your process.
 
elaine said:
I have a web appliacation, what i want to do is starting a timer when
"Application_Start" event handler is called. The timer is running
asyncronizely, let's say, every 24 hours, it will create a new thread
to run a certain process, after the process is done, the thread will
be killed.

So far, i have no idea how to do it. Can i instantiate a singleton
object in "Application_Start"? How to make a timer to be running
asyncronizely?

Please help,
Elaine


As with the others, I have to agree that creating your own services would
probably be a good idea for this. You could have the web app start the
service using the system.serviceprocess.servicecontroller class and then
have that service take over from there with its own timer and, after the
elapsed time, shut itself down. I've created similar services like this
before and its fairly easy (in most cases I'm sure).

If you need further assistance, reply back.

HTH,
Jim
 
Back
Top