[作为Windows服务运行时,.net核心3中的辅助服务未调用StopAsync

问题描述 投票:0回答:1

如果你们以前遇到过,那就太好了。我想让grpc server + web api作为Windows服务运行,因为这意味着一个长期运行的进程。 Web API基本上仅用于内部状态的运行时监视。因此,我创建了一个新的grpc服务(.net core 3),并添加了worker类,并添加了控制器等。并使用了Microsoft.Extensions.Hosting .WindowsServices nuget软件包以启用Windows服务。我使用“ sc create binpath = start = auto”来安装它,然后使用“ sc start”来启动它。观察日志文件,我可以看到它已经启动,正在访问swagger页面,我可以看到它运行良好。

当我在worker类中调用StartAsync和StopAsync时,我正在将某些内容记录到日志文件中,我可以看到,当服务启动时,将按原样调用StartAsync。

现在有趣的是,当系统重新启动时,我看不到StopAsync被调用。。

在DOS中,如果我使用dotnet .exe来运行它,则调用StartAsync,按CTRL + C停止它,然后调用StopAsync。这是windwos服务nuget包本身的错误吗?还是我在这里想念东西?

有趣的是,在Startup类中,我什至使用IHostApplicationLifetime来拦截ApplicationStarting,ApplicationStopping,但是再次,starting被调用,而stopping不被调用。为什么?

有人可以启发我吗?

.net-core windows-services background-service
1个回答
0
投票

。net核心团队的好伙伴已经知道此问题,并将在.net core 5.0中解决。参考此处:https://github.com/aspnet/Extensions/pull/2705

ETA 2020年底。

© www.soinside.com 2019 - 2024. All rights reserved.