繁体   English   中英

Topshelf超时问题

[英]Topshelf timeout issue

我们正在使用Topshelf来托管服务。 在启动服务之前,我们正在进行数据库调用以加载大量数据。 因此,在启动服务时,我们遇到以下错误:

Start Service failed with return code '[7] ServiceRequestTimeout

我们使用以下代码来启动服务:

HostFactory.Run(x =>
            {
                x.Service<AppService>(s =>
                {
                    s.ConstructUsing(name => new AppService(s_resolver, baseAddress, resolver));
                    s.WhenStarted(svc => svc.Start());
                    s.WhenStopped(svc => svc.Stop());
                    s.WhenShutdown(svc => svc.Shutdown());
                });

                x.EnableShutdown();
                x.RunAsLocalService();
                x.StartAutomatically();
                x.SetDisplayName("Application Host");
                x.SetDescription("Application Host");
            });

如果我尝试使用Visual Studio启动服务,服务运行正常。 但是当服务通过Topshelf托管时,我就错过了时间。

我也尝试使用hostControl.RequestAdditionalTime(TimeSpan.FromSeconds(300))但即使在添加额外的超时期限后,我也无法解决问题。 请提供您的建议。

HostControl.RequestAdditionalTime的文档无法说明的是,您最多只能要求60或120秒。 否则它会忽略您的请求。

它的出色记录绝对没有我所知道的地方:(如果你发现它记录在哪里,请告诉我。

这是龙

来自TopShelf

void HostControl.RequestAdditionalTime(TimeSpan timeRemaining)
    {
        _log.DebugFormat("Requesting additional time: {0}", timeRemaining);

        RequestAdditionalTime((int)timeRemaining.TotalMilliseconds);
    }

这是来自ServiceBase的JustDecompile

    /// <summary>Requests additional time for a pending operation.</summary>
    /// <param name="milliseconds">The requested time in milliseconds.</param>
    /// <exception cref="T:System.InvalidOperationException">The service is not in a pending state.</exception>
    [ComVisible(false)]
    public void RequestAdditionalTime(int milliseconds)
    {
        unsafe
        {
            fixed (NativeMethods.SERVICE_STATUS* sERVICESTATUSPointer = &this.status)
            {
                if (this.status.currentState != 5 && this.status.currentState != 2 && this.status.currentState != 3 && this.status.currentState != 6)
                {
                    throw new InvalidOperationException(Res.GetString("NotInPendingState"));
                }
                this.status.waitHint = milliseconds;
                this.status.checkPoint = this.status.checkPoint + 1;
                NativeMethods.SetServiceStatus(this.statusHandle, sERVICESTATUSPointer);
            }
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM