问题描述
我想知道,如果IDisposable的对象将在会话结束处置。
我知道,我可以在会话结束处置事件自己。但我想编写一个IDisposable接口的类。
例如,我有
公共类MyObject来:IDisposable接口
{
//一些属性 公共无效的Dispose()
{
//处理
}
}
和我需要处理会话结束时这个对象:
保护无效Session_End中(对象发件人,EventArgs的发送)
{
如果(会话[钥匙]!= NULL)
((myObject的)会议[钥匙])的Dispose();
}
所以,我想会自动知道会话结束时间的操作或我需要如上面写字。
Session_End中不会自动处置IDisposable的对象,所以你的Session_End中的解决方案是正确的。
不过:
- Session_End中只有当你用进程内会被调用(但对于其他类型的你需要一个序列化对象)
- 这只是在会话超时到期后调用,所以你一直在这个资源为额外的20分钟(或任何你超时为)
因此,尝试和发现,不需要你来了IDisposable对象存储在会话的解决方案。
I want to know if IDisposable objects will dispose on session ending.
I know, I can dispose on Session ending event myself. But I want to write an IDisposable class.
For example, I have
public class MyObject : IDisposable
{
// some properties
public void Dispose()
{
// disposing
}
}
and I need to dispose this object on session ending time :
protected void Session_End(object sender, EventArgs e)
{
if (Session["key"] != null)
((MyObject)Session["key"]).Dispose();
}
So, I want to know on session ending time that operation will automatically or I need write as above.
Session_End does not automatically dispose of IDisposable objects, so your Session_End solution is correct.
However:
- Session_End is only called when you use "inproc" sessions (but for the other types you would need a serializable object)
- It's only called after the session timeout has expired, so you kept this resource for an extra 20 minutes (or whatever your timeout is)
So try and find a solution that doesn't require you to store IDisposable objects in Session.
这篇关于会议电话可以配置在会议结束时的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!