I have a asp.net app and I have a few tasks that get called in the application start function. These tasks run is while(true) and sleep for x amount of time after the computation is done. However after deploying the app I inspected the log file that is generated by these task and saw that they are running more then they should.
In fact they run every time someone access the site after some time of inactivity.
I was looking through the Application pool settings and saw that Process Model Idle time out is set to 20 minutes.
Could this be causing the problem? i.e. does the application get restarted after very 20 minutes and therefore causing the application_start function to be called again ?
Yes, exactly. This setting means that if there’s no activity on your site (no HTTP requests) for the given time, IIS will simply unload the application domain from memory. Then the next request that comes in will start a fresh new instance of the application and Application_Start will be hit once again.
Bear in mind that this is not the only condition when IIS might unload your application. This could also happen if for example the process reaches certain thresholds of CPU or memory usage. Those are also configurable.
It will also restart if some of the files in the
binfolder are modified or theweb.configorGlobal.asaxis also modified. But this time it is not IIS that will unload the application, it is the ASP.NET runtime which listens for changes in those files. But in all cases it will result intoApplication_Startbeing triggered on the next request.