asp.net WebService中Application_End什么时候被调用
在 WebService 的情况下,Application_End 到底什么时候触发?
我读到(Application_End global.asax)每次卸载应用程序时都会调用Application_End。这是否意味着每次调用 Web 服务中的方法之后?
我有一段代码,只需在第一次调用 IIS 时触发一次,并在最后一次调用 IIS 后(以及在回收之间)再次触发,并且我不能在每个 WebService 请求和响应时触发它...
When exactly does the Application_End fire in the case of a WebService ??
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 ?
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Application_End
正是您正在寻找的内容;应用程序根据您设置的配置卸载,但默认情况下,在有任何请求进来后,它会继续运行一段空闲时间,或者在请求不断进来时保持运行状态。请注意,其他事情可以导致应用程序池刷新,从而导致调用
Application_End
;一定次数的重新编译(由于更改了 aspx 文件等)、运行一定时间段、一定量的内存压力等。同样,这些都是可配置的,但通常设置为合理的默认值。要记住的关键一点是,您可以预计
Application_Start
和Application_End
之间会有一段时间,但您无法知道会有多少时间,具体取决于关于服务器上发生的事情。另请注意,当应用程序池被回收时,已经运行的请求不会突然停止,它们实际上可能与新进程处理的新请求重叠。这意味着旧应用程序池的
End
可能会在新应用程序池的Start
之后调用。但这应该不重要,因为每个应用程序都有自己的AppDomain,并且不共享数据。 (但有时这可以解释其他奇怪的行为。)哦,最后;甚至这也是可配置的!编辑:还要添加一件事!请注意,如果服务器突然关闭,
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.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.The key thing to keep in mind is that you can expect there to be some time between
Application_Start
andApplication_End
, but you can't know how much time there will be, based on what is happening on the server.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'sStart
. 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!EDIT: One more thing to add! Note that if the server is taken down suddenly,
Application_End
would not be called.