为了能够关闭后台进程(使用 Quartz.Net 实现),我需要在 AspNet5 beta8 中检测 Web 应用程序关闭。在以前的 Asp.Net 版本中,可以在 Application_End 上执行代码。AspNet5 中的 Application_End 事件的等价物是什么?
到目前为止,我在 Configure 中尝试了 IApplicatonLifetime,但是当我停止 Web 应用程序时它不会触发:
public void Configure(IApplicationBuilder app, IApplicationLifetime lifetime)
{
lifetime.ApplicationStopping.Register(() =>
{
Logger.LogInformation("Application Stopping. Do stuff.");
});
lifetime.ApplicationStopped.Register(() =>
{
Logger.LogInformation("Application Stopped. Do stuff.");
});
}
我对 ApplicationStopping 和 ApplicationStopped 都没有任何回应。