Lets' say my IIS8 hosted web site is up and running and happily serving requests. Now, from an elevated Powershell, I run:
Stop-WebSite <MyWebSite>
My assumption until recently was that IIS would stop serving new requests, finish up current ones, and then gracefully stop the web site. However, I suspect that this is not always the case: there's a code path in my app like this:
Log("Begin");
try
{
DoSomething(); // can take a few seconds
}
finally
{
Log("End");
}
Occasionally, there would be "Begin" entries in my log without matching "End". Any chance Stop-WebSite forcefully kills the host process?
When running this simple test:
and stopping the web site a second after I called the page, I always get all six log entries.
So, in general your (and mine) original assumption is correct, the running process is finished before the site is shut down.
Is it impossible that a certain request may not finish? What if it runs for hours? what if something goes wrong and the worker process hangs?
I would look for other reasons why your 'Log("End");' does not work.