.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("应用程序退出后"); });
       }

 

posted @ 2021-06-04 14:00  b̶i̶n̶g̶.̶  阅读(239)  评论(0编辑  收藏  举报