Azure 云服务:RoleEnvironment.StatusCheck 事件未触发

Azure Cloud Service: RoleEnvironment.StatusCheck event not firing

我正在维护一个托管在 Azure 上的遗留云服务应用程序,目标是 .net 4.6.1。在 Web 角色 Global.asax 的 Application_Start 方法中,我们正在为 RoleEnvironment.StatusCheck 注册一个事件处理程序,但是我们的日志显示此事件回调从未被调用或触发。

根据此博客:https://convective.wordpress.com/2010/03/18/service-runtime-in-windows-azure/ 我们预计此事件每 15 秒触发一次,我们相信这种情况正在发生,但此后已停止。我们预计在我们将一些新的 DLL 安装到解决方案时停止工作(其中一些 dll 包括:Microsoft.Rest.ClientRuntime.dll、Microsoft.Azure.Storage.Common.dll、Microsoft.Azure.Storage.Blob.dll、Microsoft.Azure.KeyVault.dll)

我们已尝试通过 RDP 连接到 VM 上以检查事件日志,但没有任何明显的迹象。关于我们可以在哪里搜索线索的任何建议?

您的事件处理程序似乎未注册。用不同的方法尝试下面的代码:

public class WorkerRole : RoleEntryPoint
{
    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();
        }
    }

    public override void Run()
    {
        Trace.TraceInformation("Worker entry point called", "Information");

        while (true)
        {
            Thread.Sleep(10000);
        }
    }

    public override void OnStop()
    {
        base.OnStop();
    }
}