Session containing items implementing IDisposable(包含实现 IDisposable 的项目的会话)
问题描述
在 ASP.NET 中,如果项目留在会话状态中,实现 IDisposable 但在会话到期时从未被应用程序专门删除和处置,将对 Dipose() 中的任何代码将执行的对象调用 Dispose?
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 会话管理器对在实现 IDisposable
的类上显式调用 Dispose()
做出任何保证.
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
.
请注意,尽管 Mark 强烈反对,但我并不是建议常规"添加终结器.我只是建议,如果您想要在会话到期时调用的对象上的 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 的项目的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:包含实现 IDisposable 的项目的会话


- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01