首页 > 解决方案 > 有时窗口服务无法在机器重新启动时启动,手动启动并正常工作

问题描述

我有一个奇怪的行为将 asp.net web api 作为window service. 50% 的时间机器重新启动,然后服务不会自动启动,50% 的时间它正确启动。我已将其设置为自动延迟启动,这取决于另一项服务的启动。

当它无法自动启动并且我正在查看事件查看器时,我可以看到下面的应用程序错误,

CoreCLR Version: 4.700.21.31506
.NET Core Version: 3.1.17
Description: The process was terminated due to an unhandled exception.
Exception Info: System.OperationCanceledException: The operation was canceled.
at System.Threading.CancellationToken.ThrowOperationCanceledException()
at System.Threading.CancellationToken.ThrowIfCancellationRequested()
at Microsoft.Extensions.Hosting.Internal.Host.StopAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.WaitForShutdownAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at XXX.Program.Main(String[] args)

和“服务控制管理器”事件一样,

The "XXX" service failed to start due to the following error: 
The service did not respond to the start or control request in a timely fashion.

现在,当我在失败后手动启动它时,它启动时没有任何错误。

问题是,在 10 次重启中,为什么有时服务启动时没有任何错误,有时却抛出错误?它的解决方案是什么?它等待启动和失败的最大时间是多少?我可以增加一些时间线吗?

标签: c#windows-servicesasp.net-core-3.1

解决方案


推荐阅读