我们正在使用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启动服务,服务运行正常。但是,当服务是通过托架托管的时候,我得到了time out错误。
我也尝试过使用hostControl.RequestAdditionalTime(TimeSpan.FromSeconds(300)),但即使添加了额外的超时时间,我也无法解决这个问题。请提供您的建议。
发布于 2013-10-26 01:24:04
HostControl.RequestAdditionalTime的文档没有说明的是,您只能要求最多60或120秒。否则它会忽略您的请求。
在我所知道的任何地方,它都有很好的文档记录:(如果你在哪里找到它的文档,请让我知道。
发布于 2016-11-09 07:18:14
龙来了
来自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);
}
}
}https://stackoverflow.com/questions/19589686
复制相似问题