-
This simple method is taken from: http://www.qumiao.com
The following is the content of the Global.asax file.
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Timers" %>
<%@ Import Namespace="System.Net" %>
<script runat="server">
protected void Application_Start(object sender, EventArgs e) {
//Execute periodic tasks every 5 seconds
Timer myTimer = new Timer(5000);
myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
myTimer.Enabled = true;
myTimer.AutoReset = true;
}
protected void Application_End(object sender, EventArgs e) {
//The following code is the key to solving the problem of automatic recycling of the IIS application pool
//Set your web address here, you can point it to any of your aspx pages or even non-existent pages.
//The purpose is to stimulate Application_Start
System.Threading.Thread.Sleep(1000);
WebRequest.Create(" http://localhost/").GetResponse ();
}
void myTimer_Elapsed(object source, ElapsedEventArgs e) {
try { CycleTask(); } catch {}
}
void CycleTask() {
//Write here the periodic tasks you need to perform
}