微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决Azure 云服务:RoleEnvironment.StatusCheck 事件未触发

我正在维护一个托管在 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 来检查事件日志,但没有任何明显的迹象。关于我们可以在哪里寻找线索的任何建议?

解决方法

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

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();
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。