简体   繁体   中英

How to “know” of iisreset on a webservice

I have a webservice where I want to do something when a the application pool ends, so I thought I'd do:

Application_End()
{
    // Some logic here
}

What happens is if I stop the application pool, this logic is executed. On the other hand, if I just call iisreset, it is NOT.

So my question is: where should I put my code so that it is executed in both cases?

There is no guarantee that Application_End will be called. The example you mentioned, where you perform an IIS reset is an example. Other examples could include someone unplugging the server, or a hardware failure.

What I've done in the past is to use Application_Start to call my data cleanup logic as the application comes back online. This is assuming you don't need any values that were stored in memory.

I don't think you could. Imagine if your code fired off an infinite loop, you could basically kill the web server and stop it shutting down.

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