Reputation: 2951
There have been some questions about how to detect when an application is shutting down using IRegisteredObject. However, IRegisteredObject.Stop will not be invoked until all active requests complete.
This will be the case for long running requests (pushlet, long polling, web socket), meaning that an app pool recycle can be held up by these requests indefinitely.
Is there a way to detect from a long running request that an application shut down is pending?
I've already tested using IRegisteredObject or polling HostingEnvironment.ShutdownReason. Neither one works until active requests are completed.
Upvotes: 5
Views: 1473
Reputation: 2951
The Katana/Owin project accesses the internal System.Web.Hosting.UnsafeIISMethods.MgdHasConfigChanged method to detect a shutdown so that long running requests can detect this state.
See ShutdownDectector and UnsafeIISMethods for sample implementation.
Upvotes: 4