When there's no class extending RoleEntryPoint
the web role will run just fine, just no extra code is run instead of OnStart()
, Run()
and OnStop()
.
Application_Start()
is completely unrelated to Azure and is completely ignored by Azure runtime, it's just some piece of ASP.NET wiring. You can easily have Application_Start()
unconditionally throwing an exception and that won't prevent your web role from getting started, just all HTTP requests will fail.
Bear in mind that starting with SDK 1.3 the default mode is "IIS mode" where the web role payload containing RoleEntryPoint
descendant runs in one process (WaIISHost.exe) and ASP.NET code runs in another process. The process with RoleEntryPoint
is started by Azure runtime first, it runs OnStart()
and enters the infinite loop in Run()
, then the instance is opened for HTTP requests. If you use IIS 7.5 and have "autostart" enabled you may have Application_Start()
executed earlier, but otherwise you won't have Application_Start()
executed until the first request comes.
So the key is that there're two different processes running your code and each has its own lifetime and that dictates limitations on how you can design your application.
The RoleEntryPoint
descendant class can have any name, belong to any namespace and be located in any .cs file within the project which is selected as the payload for the web role - that will likely be your ASP.NET project. Under these conditions the RoleEntryPoint
descendant will be located by Azure runtime and its methods will be run as part of role instance lifetime.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…