I am looking at using QueueBackgroundWorkItem for background work items in my ASP.NET Web-API2 REST server. This works perfectly for my use case in that all jobs being run get completed and written to a DB before the web app is shut down. And the replacement web app takes over and can return the completed jobs.
However, when I complete a job in the background thread, I don't want to start another if IIS wants to shut the app down. Is there a way to find out if IIS is waiting on tasks to complete and will then be shutting down?