As noted by the British developer, the Windows Azure Fabric Controller decides which instances will be closed. You cannot control this process. I donβt think this is always the last number, because Iβm not sure if the fabric controller stops renaming instances after closing. Thus, even if it turns off IN_1, at the end of the process we will still have IN_0 and IN_1, for example, with the setting IN_0 and IN_2.
You can use the RoleEnvironment.Stopping event to handle the proper stop (clean shutdown) of your instance. This event occurs after the VM has been taken out of the rotation of the Load Balancer and before the OnStop Method of your called RoleEntryPoint class.
I'm not sure where I noticed this, but I know that there is a difficult time line in which you must complete the cleanup, that is, I think the instance will be turned off after 5 minutes of waiting for the OnStop or Stopping handler (I donβt remember exactly, but the fabrci controller will not wait long until you clean it).
source share