.net5 应用程序启动和停止事件
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime hostApplicationLifetime) { hostApplicationLifetime.ApplicationStarted.Register(() => { Console.WriteLine("应用程序启动后"); }); hostApplicationLifetime.ApplicationStopping.Register(() => { Console.WriteLine("应用程序退出前"); }); hostApplicationLifetime.ApplicationStopped.Register(() => { Console.WriteLine("应用程序退出后"); }); }