什么时候在ASP.NET Web服务中调用Application_End [英] When is Application_End called in asp.net WebService

查看:131
本文介绍了什么时候在ASP.NET Web服务中调用Application_End的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用WebService的情况下,Application_End何时确切触发?

When exactly does the Application_End fire in the case of a WebService ??

我读到( Application_End global.asax ),每次在应用程序被调用时都会调用Application_End卸载.这是在每次调用Web服务中的方法之后意味着什么?

I read (Application_End global.asax) that the Application_End is called everytime the application is unloaded. Does this mean after every call to a method in a web service ?

我有一段代码只需要在第一次调用IIS时触发一次,然后在最后一次调用IIS之后(以及两次回收之间)触发一次,就不能在每个WebService上都触发一次请求和响应...

I have a piece of code that I need fired only once on the first call to the IIS, and again after the last call to the IIS (and between recycles), and I can't have it being fired upon every WebService request and response...

推荐答案

Application_End正是您想要的;该应用程序会根据您设置的配置进行卸载,但默认情况下,它将在任何请求进入后继续运行一定时间的空闲时间,或者在请求不断进入时保持运行状态.

Application_End is exactly what you are looking for; The application is unloaded according to the configuration you set, but by default it will continue running for a certain amount of time of being idle after any requests come in, or it will remain running while requests are continually coming in.

请注意,其他事情可能导致应用程序池刷新,因此导致调用Application_End;一定数量的重新编译(由于更改了aspx文件等),一定的运行时间,一定数量的内存压力等.同样,这些都是可配置的,但通常设置为合理的默认值.

Note that other things can cause the App Pool to refresh, and therefore cause Application_End to be called; a certain number of recompiles (due to changed aspx files, etc), a certain time period running, a certain amount of memory pressure, etc. Again, these are all configurable, but are set to reasonable defaults, generally.

要记住的关键是,您可以期望在Application_StartApplication_End之间有一些时间,但是根据服务器上发生的事情,您不知道会有多少时间.

The key thing to keep in mind is that you can expect there to be some time between Application_Start and Application_End, but you can't know how much time there will be, based on what is happening on the server.

还要注意,当回收应用程序池时,已经在运行的请求不会突然停止,实际上它们可能与新进程正在处理的新请求重叠.这意味着旧应用程序池的End在新应用程序池的Start之后可能被称为.但这无关紧要,因为每个应用程序都有自己的AppDomain,并且不共享数据. (但是有时候这可以解释奇怪的行为.)哦,最后;甚至也是可配置的!

Also note that when an App Pool is recycled, already-running requests are not stopped suddenly, and they may in fact overlap with new requests being handled by the new process. This means that an old app pool's End might be called after the new app pool's Start. But this should not matter, because each app has it's own AppDomain, and doesn't share data. (but sometimes that can explain otherwise weird behavior.) Oh, and finally; even that is configurable, too!

要添加的一件事!请注意,如果服务器突然关闭,则Application_End不会被调用.

One more thing to add! Note that if the server is taken down suddenly, Application_End would not be called.

这篇关于什么时候在ASP.NET Web服务中调用Application_End的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆