开发者

Is it possible for RoleEntryPoint.OnStart() to be run twice before the host machine is cleaned up?

开发者 https://www.devze.com 2023-03-13 06:44 出处:网络
I plan to insert some initialization code into OnStart() method of my class derived from RoleEntryPoint. This code will make some permanent changes to the host machine, so in case it is run for the se

I plan to insert some initialization code into OnStart() method of my class derived from RoleEntryPoint. This code will make some permanent changes to the host machine, so in case it is run for the second time on the same machine it will have to detect those changes are already there and react appropriately and this will require some extra code on my part.

Is it possible OnStart() is run for the second time before the host machine is cleared? Do I need this code to be able to run for the secon开发者_高级运维d time on the same machine?


Is it possible OnStart() is run for the second time before the host machine is cleared?

Not sure how to interpret that.

As far as permanent changes go: Any installed software, registry changes, and other modifications should be repeated with every boot. If you're writing files to local (non-durable storage), you have a good chance of seeing those files next time you boot, but there's no guarantee. If you are storing something in Windows Azure Storage (blobs, tables, queues) or SQL Azure, then your storage changes will persist through a reboot.

Even if you were guaranteed that local changes would persist through a reboot, these changes wouldn't be seen on additional instances if you scaled out to more VMs.


I think the official answer is that the role instance will not run it's Job more than once in each boot cycle.

However, I've seen a few MSDN articles that recommend you make startup tasks idempotent - e.g. http://msdn.microsoft.com/en-us/library/hh127476.aspx - so probably best to add some simple checks to your code that would anticipate multiple executions.

0

精彩评论

暂无评论...
验证码 换一张
取 消