谁能向我解释为什么我的服务器无缘无故停止了?
下面是我的 IHostedService 实现:
public class HostServiceBox : IHostedService
{
public Task StartAsync(CancellationToken cancellationToken)
{
return Task.Run(() =>
{
DomonutyBoxBusiness.StartBoxListening(); //STARTUP Box listening
while (true)
{
Logging.Info(DateTime.Now + " HostServiceBox Running");
Thread.Sleep(10000);
}
}, cancellationToken);
}
public Task StopAsync(CancellationToken cancellationToken)
{
Logging.Info(DateTime.Now + " StopAsync");
//TODO impplement a Stop litening all boxes
throw new NotImplementedException();
}
}
这是我的日志?
.....
2/24/2018 8:31:27 PM HostServiceBox Running
2/24/2018 8:32:27 PM HostServiceBox Running
2/24/2018 8:33:27 PM HostServiceBox Running
2/24/2018 8:34:27 PM HostServiceBox Running <------
2/25/2018 11:22:07 AM HostServiceBox Running <-----
2/25/2018 11:23:07 AM HostServiceBox Running
2/25/2018 11:24:07 AM HostServiceBox Running
2/25/2018 11:25:07 AM HostServiceBox Running
......
看起来像在 IIS 上使用 kestrel (.Net Core) 我的方法休眠了吗?为什么?
通常我的而(真)重新启动,因为我调用了API。但托管服务是一个后台任务,它不应该停止,对吧?
相关帖子github
用户tym32167走在正确的轨道上。文档中提到了这一点IHostedService
在关于部署:
在 IIS 或常规 Azure 应用服务上,您的主机可能会因应用程序池回收而关闭
IIS 应用程序池的默认空闲超时时间为 20 分钟,并且默认的应用程序池回收时间为 29 小时。通常,您希望将空闲超时设置为零(禁用),并将回收时间设置为危害最小的固定时间。
有一篇有趣的博客文章介绍了他们为什么选择 29 小时here它还涵盖空闲超时。
此外,如果您碰巧要部署到 Azure,前面链接的那篇文章建议了真正全职运行的其他部署方法(容器、WebJobs 等)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)