Search code examples
azure-web-app-serviceblazor-server-sidevisual-studio-debugging

Is there a way to gently shut down the Visual Studio web server


I have some code in my Blazor server app that, I believe, runs when IIS shuts down (via IDisposable). Is there a way, when running under the Visual Studio debugger, to have it perform the shutdown notifications/operations that occur when running on Azure App Server and it gently shuts down there?


Solution

  • Try this

    app.Lifetime.ApplicationStopping.Register(() => Console.WriteLine("Stopping")); 
    

    in program.cs and then use Ctrl-C in the console that is running the app, it triggers a shutdown and runs that code.