I saw an internal discussion that had some information I thought would be useful to share. It’s about how some of the methods in RoleEntryPoint get called.
In the case of a Worker Role, the RoleEntryPoint class is the class you derive to write your code. When you create a new Worker Role project in Visual Studio, you’ll see that the project contains one code file and in that code file there is a class called WorkerRole that derives from RoleEntryPoint.
Worker Role Call Order:
WaWorkerHost process is started.
For step 1 above, Windows Azure only loads one assembly and takes the first class that derives from RoleEntryPoint that it finds. Visual Studio knows which assembly implements RoleEntryPoint based on the reference to the project under the Roles node.
That reference is a project to project reference that is passed through to packaging. This puts a file called __entrypoint.txt in the Service Package than contains the name of the assembly that has a class that derives from RoleEntryPoint.
In the case of a Web role, a RoleEntryPoint derived class is actually not required. That said, in the Visual Studio web role templates, we add a file called WebRole.cs that includes an implementation of OnStart() specifically to add template code to show you how to startup the the Diagnostic Monitor and to show you how to hook into configuration setting changes. (i.e. when a new serviceconfiguration.cscfg file is uploaded to the cloud)
Web Role Call Order:
You can implement a RoleEntryPoint.Run() method in a WebRole, it’ll get called on a new foreground thread that executes in parallel with RoleEntryPoint.OnStart().
Thing is, if you exit from the RoleEntryPoint.Run() method, (the default implementation just waits on an infinite Thread.Sleep()) your role is going to recycle – so just be aware of that consequence, almost certainly not what you want in a web role (the role will be offline while it starts up again).
What causes the Worker Role in the development fabric to exit when the IE window to the web role is closed? It doesn't seem like OnStop is called in this case - is that just a dev fabric issue?
We stop debugging when the IE window to the web role is closed similar to how we stop debugging and ASP.NET Web Application project when you close IE.
Stopping debugging stops the whole service deployment in the devfabric, that's why you see the worker role exit.
You can configure VS not to launch a browser for the web role and then if you bring it (IE) up separately, you can close it and not have the deployment stop. You can do that by right clicking on the role node in the cloud service project and select "properties". The setting is at the bottom of the configuration page.
Is the call order valid for full IIS too (or only for HWC)?