How does app_offline.htm, stopping an IIS Site and Stopping an App Pool affect currently running threads?
If I:
- put an
app_offline.html
in the website root - stop an IIS 7.5 site
- stop an IIS 7.5 App Pool
What happens to currently running threads (in all three cases) including background threads? Are they all immediately terminated, or are run开发者_开发技巧ning ones allowed to finish?
Thanks
Andrew
By adding the app_offline.htm the application send the Application_End
and after this function return the rest of the threads of the program are killed. The maximum time of wait for the Application_End
to return is set on the pool settings.
If you stop the full pool then all the sites that under this pool follow the same procedure. If you only open the app_offline.htm then only this site affected.
To avoid your threads to kill by this shutdown, set a wait state on the Application_End
void Application_End(object sender, EventArgs e)
{
// This is a custom function that you must make and
// check your threads in the program
MyTheadClass.WaitForAllMyThreadsToExist();
// after this function exit the rest of the threads are killed.
}
One more note.
All the time that you wait on Application_End for your threads to exit from the wait state (of a mutex probably) the site is not longer accept web connections and it seems like not responding. So its up to you to make your threads exit as soon as possible when you get this message.
Just noting that the file name must be app_offline.htm. Using app_offline.html will not work!
When app_offline.html is put:
Based on ScottGu's this article it says the app domain is unloaded. And based on this article, all background threads are stopped when the app domain is unloaded and ThreadAbortException is thrown.
I'm not sure about stopping the site but stopping the App Pool should have the same effect.
精彩评论