I have an IIS application that has a long-lived singleton. On rare occasion, this singleton hangs when trying to obtain a resource. It is known that recycling the application pool will cause the resource to became available again. Assuming this rare event can be trapped by the application itself using a StopWatch
or similar, upon doing so, can the event handler in the application itself recycle the application pool? This is a severe thing to do, but it is better than letting it hang until the next IIS scheduled recycling. The cause of the hang is related to that resource and its interaction with IIS, and I have no means to fix that. Note the call to get the resource is synchronous. If so, please provide information about how to do so.
Response to comments Regarding Restarting the Application Domain and Recycling the Application Pool my observations are that restarting the Application Domain is one of the causes of the hang. The resource is an unruly native dll that is loaded by code other than my own. Perhaps I find an API to unload and load the unruly unmanaged dll. But for now, I have been manually, not programmatically, recycling the application pool to restore operations.
Upon Recycling the Application Pool, the Destructor of the Singleton is called, and therein the resource, after a call to the external API, Dispose(), is put into a good state, presumably unloaded, but I have yet verify that.