有人可以解释一下为什么我的服务器无缘无故停止了吗? 以下是我的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
......
为什么在使用Kestrel (.Net Core)的IIS时我的方法会挂起?
通常情况下,由于调用API,我的< strong>while(true)代码块会重新启动。但是作为后台任务的< strong>IHostedService不应该停止,对吗?
相关帖子请参考github
事件查看器(Event Viewer)
中是否有任何有趣的信息? - mjwills