Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating the Timer in Global.asax file

I would like to execute a storedprocedure for evey one hour and have to load the dataset in applicaion(dropdrown or some asp.net controle) by creating the timer in Global.asax file.

Am very very new for this kind of development, please any one could post the code or provide the exact flow what i have to do in coding and how to load the asp.net controls(dropdown or list controle).

Thank You in Advance,

like image 483
Software Enginner Avatar asked Jul 12 '12 12:07

Software Enginner


2 Answers

Scheduling tasks like that is not an appropriate use for an aspx application.

However, there are several hacks/workarounds you can try:

http://www.codeproject.com/Articles/12117/Simulate-a-Windows-Service-using-ASP-NET-to-run-sc

http://www.west-wind.com/weblog/posts/2007/May/10/Forcing-an-ASPNET-Application-to-stay-alive

http://www.mikesdotnetting.com/Article/129/Simple-task-Scheduling-using-Global.asax

You would be much better off creating windows service or use the built-in Windows scheduler.

like image 89
Steve Wellens Avatar answered Sep 19 '22 03:09

Steve Wellens


ASP.NET is the wrong tool for the job.

A web application is, by design, a request-response system. It listens for requests, processes those requests, and returns responses. Outside of that scope, it should be assumed that the application isn't running. (Indeed, IIS might shut down the application for any number of reasons, waking it again on the new request.)

What you want for a scheduled task is probably a Windows Service. This is designed to run in the background on the server. Including a timer is pretty straightforward and it can run tasks in response to that timer's tick event.

Thinking about it... What would the web application do when the timer ticks? How would it "load the data into some asp.net control" if it's executing a background-process and not actually responding to a web request? Without a page being requested, there is no page to show to the user.

The way I imagine this would work is that the Windows Service would be reading some data, running some business logic to transform that data, and writing the transformed data to another table or set of tables in the database. The web application would then just always refer to that other table or set of tables when it populates the controls on its pages. Essentially, the web application would have no knowledge of the back-end process that transforms the data. It just shows whatever the latest transformed data happens to be.

like image 45
David Avatar answered Sep 19 '22 03:09

David