To implement the above functions in a project, add a global. aspx file to the project.
Public class Global: system. Web. httpapplication
{
Protected void application_start (Object sender, eventargs
E)
{
// Define the timer
System. Timers. Timer
Mytimer = new system. Timers. Timers (5000 );
Mytimer. elapsed + = new
Elapsedeventhandler (mytimer_elapsed );
Mytimer. Enabled =
True;
Mytimer. autoreset = true;
}
Void mytimer_elapsed (Object source, elapsedeventargs E)
{
Try
{
Log. savenote (datetime. Now. tostring ("yyyy-mm-dd hh: mm: SS") + ": autotask is
Working! ");
Yourtask ();
}
Catch
(Exception ee)
{
Log. saveexception (EE );
}
}
Void yourtask ()
{
// Write the task you want to execute here
Log. savenote (datetime. Now. tostring ("yyyy-mm-dd
Hh: mm: SS ") +": Start of collection! ");
}
Protected void application_end (Object sender, eventargs
E)
{
Log. savenote (datetime. Now. tostring ("yyyy-mm-dd
Hh: mm: SS ") +": Application end! ");
// The Code below is the key, this solution solves the issue of automatic collection of IIS application Programs pools
thread. sleep (1000);
// set your web address here to point to any of your Aspx pages or even non-existent pages, the purpose is to activate application_start.
String url = "http: // localhost: 8031/default. aspx ";
Httpwebrequest myhttpwebrequest =
(Httpwebrequest) webrequest. Create (URL );
Httpwebresponse
Myhttpwebresponse =
(Httpwebresponse) myhttpwebrequest. getresponse ();
Stream
Receivestream = myhttpwebresponse. getresponsestream (); // get the write-back byte stream
}
}
Original article:
Http://www.cnblogs.com/yangxiaohu1/archive/2010/02/06/net-autotask.html