I ve started a timer to开发者_JAVA技巧 visit my application every 20 minuates in Applicaiton_start
in global.asax
.
void Application_Start(object sender, EventArgs e)
{
System.Timers.Timer tm = new System.Timers.Timer(20 * 60 * 1000);
tm.Elapsed += new System.Timers.ElapsedEventHandler(tm_Elapsed);
}
void tm_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
System.Net.WebRequest rqst = System.Net.WebRequest.Create("MySite URL");
rqst.GetResponse();
}
Is this a safe way or anyother ways. I am doing so to execute schedule jobs using quartz.net...
While autopinging your application is one way of keeping it alive you could also configure the application pool in IIS to not recycle:
Just uncheck the Shutdown worker processes after being idle for
checkbox. Also on the Recycling
tab you will find other useful options.
You should just be able to modify IIS to do this. IIS is set up to take down applications after 'x' minutes of inactivity. Your code would probably stop the site being taken down due to inactivity.
However, IIS is also by default set to recycle applications every 'x' minutes/hours. Your code would not stop this. It happens regardless of activity. It is designed to clear up any memory leaks, etc. so if you switch this off (you can do that in IIS too) then you must be carefull that your sites performance does not degrade over time.
精彩评论