使用Microsoft.AspNet.Server.Kestrel时是否有关机功能? ASP.NET核心(以前的ASP.NET vNext)显然有一个启动顺序,但没有提到关机序列以及如何处理干净的关闭.
解决方法
在ASP.NET Core中,您可以注册到IApplicationLifetime提供的取消令牌
@H_404_6@public class Startup
{
public void Configure(IApplicationBuilder app,IApplicationLifetime applicationLifetime)
{
applicationLifetime.ApplicationStopping.Register(OnShutdown);
}
private void OnShutdown()
{
// Do your cleanup here
}
}
IApplicationLifetime还会显示ApplicatoinStopped和ApplicationStarted的取消令牌以及StopApplication()方法来停止应用程序.