0

We have an OWIN application running on IIS and are currently using the AppProperties(IAppBuilder.Properties).OnAppDisposing cancellation token to detect when the application is being shutdown to gracefully shutdown some of the long running tasks that we start when the application starts.

The problem is that when the web.config is modified (even if just doing a "touch web.config") then the OnAppDisposing cancellation token is cancelled and our long running tasks shut themselves down. But the application pool is not actually recycled in these cases and so our long running tasks do not get restarted until the app pool is actually recycled.

How is one supposed to handle web.config changes in these instances? So that we can still detect OnAppDisposing and shutdown gracefully while also not have to worry about long running tasks shutting down and not getting started again?

Update: I've found that the OWIN app will get initialized again when the first http request comes in. But if there were Hangfire or other Background tasks that you expected to be running they won't be started again until that web request comes in. Even if you have application initialization setup, the appinit url is not hit after the app domain restart.

mkinkade
  • 315
  • 2
  • 10
  • "But the application pool is not actually recycled" is by design, as ASP.NET runtime only unloads the app domain and loads a new one. So you should revise your design to work with that (to start the long running tasks when the new app domain is up). – Lex Li Jul 13 '20 at 13:59
  • How do we detect when new app domain is loaded? OWIN startup class Configure method is not run again and the application initialization method is also not run again. – mkinkade Jul 13 '20 at 14:14
  • Possible duplicate: https://stackoverflow.com/questions/613824/how-to-prevent-an-asp-net-application-restarting-when-the-web-config-is-modified/31470150#31470150 – Bruno Jul 13 '20 at 14:20

0 Answers0