What is the most effective way to execute a method in the Global.asax file every x number of minutes? Is there a way to have the ASP.NET server run a background thread that fires a tick event after a certain elapsed period?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You could have a timer in the Application_Start of the Global.asax, but this is not very flexible since you need to do a request to the application for the timer to start. There are dangers to doing it this way though, as detailed by Haacked:
A better way of doing it is to have a web service that acts as an interface to your ASP.NET application and have a windows service that calls your web service on scheduled intervals:
More details here:
Method 2
you could use combination of HTTPModule and ASP.NET TIMER to do this
(or)
You could use AJAX Timer control .
http://technico.qnownow.com/2012/06/12/refresh-gridview-intervals-using-ajax-timer/
Method 3
Put a System.Timers.Timer object in Application_Start () in Global.asax.
http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0