Why does Application_Start fire several times in Global.asax?

I have a Silverlight application hosted on an ASP.NET page. I need to do some processing when the application starts up first and starts some background processes (various periodic checks).

I thought that the Global.asax Application_Start event would be a good place for this, but I found Application_Start to fire several times, which I did not expect. From what I read, it seems that when the last user exits my application, their session disappears and IIS unloads my application. When it is requested, it will load again, and Application_Start will start again, which I do not want.

Is this the expected behavior? Is there a way to keep the application loading and not restarting it?

Secondly, I have these periodic background processes that I want to start. Perhaps the Windows Service will be the best place for them, but using a timer from a static class in my application will be convenient. Is there a way to preserve these features, even if there are no active users?

+4
source share
1 answer

I think you are trying to achieve behavior that just does not fit the web server model. Many CMS try to perform periodic tasks, etc. When some user web requests initiate work, but I have never seen it with great success.

If you are not limited to deployment issues, permissions, etc., I would recommend using the Windows Service approach. Just remember to include it in the build / deployment process so that it does not become dangerous.

+2
source

Source: https://habr.com/ru/post/1301966/


All Articles