简体   繁体   中英

ApplicationPool class stopped event

I am using the ApplicationPool class's ApplicationPool.Stop method to stop the app pool via C# code. This method stops the app pool, it is fine. But the issue is that I want to detect when the pool has stopped since that method takes some time to make the app pool in stopped state. Is there any event which I should wire to detect whether the app pool has stopped?

Edit: I can't use Global.asax (of site of which I am stopping the app pool) since I am stopping the app pool from another application.

You can SpinWait until your application pool is stopped. Something like this:

ApplicationPool pool = //your pool here.
pool.Stop();
if (SpinWait.SpinUntil(() => pool.State == ObjectState.Stopped, TimeSpan.FromSeconds(30)))
{
    //The application pool has stopped
}
else
{
    //The application pool did not stop within 30 seconds.
    //An error probably occured.
}

You don't have to specify a timeout, however I would strongly recommend it. If you don't, you risk completely blocking the rest of your process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM