包含会话项目实施了IDisposable [英] Session containing items implementing IDisposable

查看:112
本文介绍了包含会话项目实施了IDisposable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET如果物品留在实现IDisposable会话状态,但从来没有明确删除并当会话过期将部署上的对象称为应用程序处理任何code在Dipose()将执行?

In ASP.NET if items are left in the session state that Implement IDisposable but are never specifically removed and disposed by the application when the session expires will Dispose be called on the objects that any code in Dipose() will execute?

推荐答案

如果在的IDisposable 模式的实施得当,然后是(即类的析构函数会照顾处置的对象)。我不相信ASP.NET会话管理,使约显式调用任何保证的Dispose()的实现类的IDisposable

If the IDisposable pattern is implemented properly, then yes (i.e. the class's destructor will take care of disposing the object). I don't believe the ASP.NET session manager makes any guarantees about explicitly calling Dispose() on classes implementing IDisposable.

请注意,尽管马克的激进反对,我不是例行公事,并称终结。我只是建议,如果你的希望在对象上的的Dispose 方法当会话过期叫,这是一个可行的选择。

Note that despite Mark's aggressive objections, I am not suggesting "routinely" adding finalizers. I am simply suggesting that if you want the Dispose method on your object called when the session expires, this is a viable option.

这篇关于包含会话项目实施了IDisposable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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