我们使用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))
,但即使添加了额外的超时时间后,我仍无法解决问题。请提供您的建议。
topshelf-4给你x.SetStartT imeOut(Timespan)和x.SetStopTimeout(TimeSpan) – BozoJoe