What starts first Application_Start or WebRole's OnStart?

我的未来我决定 提交于 2019-12-30 18:57:08

问题


I have MVC project on Windows Azure. This project has WebRole with method OnStart. And I want to know what starts first Application_Start of Global.asax or WebRole's OnStart?


回答1:


Pretty sure this is non-deteministic after SDK 1.3. Trying to time something from one to the other will just end in a race condition.

Prior to 1.3, the Hosted Worker Core (HWC) was hosted in the RoleEntryPoint, so there was a deterministic startup (OnStart, Application_OnStart, IIRC). However, with IIS hosting the web now, it is the IISConfigurator.exe that creates the app pool, etc, and eventually w3wp.exe hosts your web site. This is a different process than your RoleEntryPoint, so either one could start first.




回答2:


I can't find any 100% complete references on this (about the best I've seen is http://blog.syntaxc4.net/?p=271), but I believe the sequence is:

  • Any startup tasks are run
  • WebRole OnStart method is called
  • The WebRole Run() method is called - and at the same time IIS starts the websites - so at this point Application_Start will get called for the first time.



回答3:


According to Microsoft's documentation, the Application_Start method is called after the OnStart method.



来源:https://stackoverflow.com/questions/6704472/what-starts-first-application-start-or-webroles-onstart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!