2012-05-11 97 views

回答

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

相關問題