I have an ASP.NET application and I would like to have some code run
on the server automatically once a day at a specified time.
I create a timer thread to call a simple callback in the
Application_Start method. It seems to call the callback once or twice
while the application starts up but appears to stop once the default
page is displayed. Here is the code below (from Global.asax.cs):
public static void ProcessAccounts (object state) {
StreamWriter writer = new StreamWriter (@"c:\temp\testcallback.txt",
true);
writer.WriteLine (DateTime.Now.ToLongTimeString ());
writer.Close ();
}
protected void Application_Start(Object sender, EventArgs e)
{
TimerCallback callback = new TimerCallback (ProcessAccounts);
Timer timer = new Timer (callback, null, 0, 5000);
}
Any help would be much appreciated.
Cheers,
Todd.