【发布时间】:2016-01-31 04:01:10
【问题描述】:
为了能够关闭后台进程(使用 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 的任何响应。
【问题讨论】:
标签: asp.net-mvc asp.net-core asp.net-core-mvc application-shutdown