开发者

Question regarding IHttpModule.Dispose and Application_End

I was just reading this post "When is IHttpModule.Dispose method called?" I found this

"The Dispose method performs any final cleanup work prior to removal of the module from the execution pipeline."

which would mean it's application-wide.

It's ok. Anyway trying by myself I found out that using the IHttpModule Dispose method and an event handler for the Applica开发者_StackOverflow中文版tion.Disposed event should be barely the same. The first occurs right after the second one.

I don't feel this is 100 % correct i.e IHttpModule.Dispose is not always followed by Application_End. Let's say I have multiple instances of Application object running for my application which means each instance of Application object will have individual instances of modules inside it. Now let's assume a time comes when Application pool gets full with applications instances, what will happen then? Won't it be start disposing the application instances one by one and in the chain the modules inside the application instance will be disposed. Now this disposal of module doesn't mean that Application_End is going to fire after that. Application is still running. Am I right?


Yes.

HttpModules are per HttpApplication. Contrary to what its name suggestion, the Application_End method in global.asax is NOT fired at the end of each HttpApplicaton's lifetime. It is fired at the end of ALL HttpApplications' lifetimes in the current AppDomain (when the AppDomain gets torn down). The same is true for the Application_Start method.


There's only ever 1 instance of the application object per application. there are many session objects each dealing with requests, or waiting to be recycled.

The app pool won't get full of app objects as there's only 1 per application. When an app pool host more than 1 app, then there will be many and recycling the pool will kill them. App pools also have health monitoring on them that will restart the process after a certain amount of requests/memory usage. in that case existing sessions are left to die whilst a new app is started to handle new requests. when all the sessions in the old app are dead that app is torn down.

See MSDN for more details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜