There is a general approach to achieving the goal.
Firstly, your main instance. You can make your check based on the instance id. This is pretty easy. You need RoleEnvironment.CurrentRoleInstance to get the "Current Instance", now compare the Id property to what you get from RoleEnvironment.CurrentRoleInstance.Role.Instances the first element ordered by ID. Sort of:
var instance = RoleEnvironment.CurrentRoleInstance; if(instance.Id.Equals(instance.Role.Instances.OrderBy(ins => ins.Id).First().Id)) {
Now you need to select the wizard for "Healing" / recycling. You need to get the RoleEnvironment Changed event. Check that it is a TopologyChange (just check if this topological change has changed, you do not need an exact topology change). And if it is a Topological change, choose the next wizard based on the above algorithm. Check out this great blog post on how to accurately bind and change events.
Forgot to add.
If you like locks - renting a blob is the best way to acquire / check locks. However, working only with RoleEnvironment events and simple wizard selections based on instance ID, I don’t think you need this complicated locking mechanism. In addition, everything runs in the queue until it is successfully processed. . Therefore, if a master dies before he processes something, the “next master” will process it.
source share