Reputation: 1
I have a loop that is supposed to run for 120 minutes, but it always stops suddenly after about 20 minutes.
My code:
var sw = new Stopwatch();
sw.Start();
int tineout = 120 * 60000;
while (sw.ElapsedMilliseconds < tineout)
{
}
w.Stop();
return;
Upvotes: 0
Views: 181
Reputation: 415690
IIS will kill your app pool thread after 20 minutes of idle time by default, to save resources. If you keep getting requests, the thread will stay alive. In this case, "idle" means no new HTTP requests, so even though you're still doing work, it's still idle from the perspective of this timeout.
You can change this; 20 minutes is just a default. Or you can set up monitoring for the site using a free service like UpTime Robot to send (and report!) periodic requests and therefore keep the App Pool from going idle. You should be doing that anyway.
But probably you're better off thinking of a different way to do whatever long-running task this is.
Upvotes: 3