0

Why isn't this working? IIS kills my app anyway after 20 mins

    protected void Application_Start()
    {
        Task.Factory.StartNew(() => DaemonStuff());
    }

    private void DaemonStuff()
    {
        // Ping to self
        MyWebRequest selfRequest = new MyWebRequest(MyURL, "GET");
        selfRequest.GetResponse();

        // Sleep
        Thread.Sleep(1000 * 60 * 5);

    }

What I'm doing here is visiting my own site (with a webrequest) every 5 minutes.

This way, IIS shouldnt think my site is idle, because its getting visits, but it kills the app anyway.

So: is it possible to fake visits to my own site every 5 minutes so that it doesn't get killed?

sports
  • 7,851
  • 14
  • 72
  • 129

2 Answers2

0

The problem is that ASP.NET doesn’t know about work done on a background thread spawned using a timer or a task. It only knows about work associated with a request. ASP.NET simply don't know the work you’re doing and this will not prevent IIS/ASP.NET to turn off your web site.

A more robust solution is to use IRegisteredObject as explanained here.

At last, are you sure that MyURL is correct ? Check IIS Logs for this.

At last², maybe the best solution is to disable idle timeout in IIS : simply change 'Idle Timeout' in the pool's advanced settings.

Cybermaxs
  • 24,378
  • 8
  • 83
  • 112
  • Respect to your first paragraph: the work done by that timer/task is a visit... so IIS or ASP.NET should take this as a normal web client (like a browser opening the site). Maybe IIS idle timeout doesn't consider "local visits" ? – sports Jul 22 '13 at 15:45
0

The code you posted actually calls DaemonStuff() just once. That method then sleeps and returns. You should use a timer or something similar to call it repeatedly, unless I'm missing something in the code you posted.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Martin Ferrari
  • 186
  • 1
  • 7