Timer on Website to activate Web Service calls every hour
If I want to run a series of Web service calls every hour. How can I do that from my Web Server?
I'm guessing there is a timer which needs to be deployed somewhere so it counts down and when the time is up, it would 开发者_C百科consume those Web service again and retrieve the returned XML data to be stored in database. Then the timer resets again.
If you want to do this from within an ASP.NET web application, check out the Quartz.NET Job Scheduler, it's perfect for this sort of thing.
Otherwise you could run a separate application as Windows Service with a timer, or a console application as a Windows scheduled task.
You can use System.Threading.Timer class with application Start event in global.asax:
protected static Timer timer;
protected void Application_Start(Object sender, EventArgs e)
{
timer = new Timer(MyRoutineToCall, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1));
}
protected void MyRoutineToCall(Object state)
{
// do your stuff here
}
Why not just use cron? Cron is set up to do just this sort of thing.
The Windows Task Scheduler may be what you need.
Another approach is to use an IIS Auto-Start website contaning your Windows Service logic. The IIS Auto-start is supierior to using a Windows Service as it contains all the IIS application hosting logic including auto-restart, and aggressive resource management. A poorly written Windows Service can take down a Server but it takes a lot for an ASP.net IIS hosted application to take down its host (its almost impossible).
Auto Starting Websites
精彩评论