ASP.NET Core中的Startup.cs中的asp.net-core – Kestrel关闭功能

前端之家收集整理的这篇文章主要介绍了ASP.NET Core中的Startup.cs中的asp.net-core – Kestrel关闭功能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用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()方法来停止应用程序.

原文链接:https://www.f2er.com/netcore/246080.html

猜你在找的.NET Core相关文章