views:

43

answers:

2

I ve started a timer to 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...

+3  A: 

While autopinging your application is one way of keeping it alive you could also configure the application pool in IIS to not recycle:

alt text

Just uncheck the Shutdown worker processes after being idle for checkbox. Also on the Recycling tab you will find other useful options.

Darin Dimitrov
@Darin whether my method is safe?
Pandiya Chendur
@Darin i am shared hosting so i cant do all these...
Pandiya Chendur
@Pandiya - if you're in a shared hosting environment then there is nothing you can do to stop the recycling - see my answer -that happens no matter how busy the site is at the time.
Paul Hadfield
+1  A: 

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.

Paul Hadfield
@Paul i am shared hosting so i cant get iis settings
Pandiya Chendur
I'm guessing the best you can do in that case is what you suggest - but I'd set the timer to 19mins. If IIS is set to take down your site after 20mins of inactivity, you don't want your timer set to 20mins too.
Paul Hadfield
@Paul ya did that...
Pandiya Chendur