0

我正在维护一个托管在 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)

我们已经尝试在 VM 上进行 RDP-ing 以检查事件日志,但没有明显的迹象。关于我们可以在哪里寻找线索的任何建议?

4

1 回答 1

0

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

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();
    }
}
于 2021-01-06T07:36:35.607 回答