2

有什么方法可以将 vm 角色实例的状态从忙碌更改为就绪。如果可能的话,我想用 wcf 服务来做到这一点。非常感谢。

4

1 回答 1

4

Fabric Controller 将定期检查您的实例的状态,当这样做时,您将能够让它知道实例是否繁忙。

您只需处理StatusCheck事件并将其设置为忙(通过调用SetBusy方法)。一旦您确定实例已准备好(不再忙),请停止调用SetBusy方法。

public override bool OnStart()
{
   RoleEnvironment.StatusCheck += RoleEnvironmentStatusCheck;

   return base.OnStart();
}

// Use the busy object to indicate that the status of the role instance must be Busy
private volatile bool busy = true;

private void RoleEnvironmentStatusCheck(object sender, RoleInstanceStatusCheckEventArgs e)
{
   If (this.busy)
   {
      // Sets the status of the role instance to Busy for a short interval.
      // If you want the role instance to remain busy, add code to 
      // continue to call the SetBusy method
      e.SetBusy();
   }
}

参考:http: //msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.statuscheck.aspx

于 2012-05-11T11:39:39.270 回答