我们可以/是否需要

编程入门 行业动态 更新时间:2024-10-22 17:19:59
本文介绍了我们可以/是否需要-在aspx.cs类中实现IDisposable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

公共局部类SelectForm:BasePage,IDisposable {

public partial class SelectForm : BasePage,IDisposable {

public override void Dispose() { Dispose(true); GC.SuppressFinalize(this); }

protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { #region Objects which are getting disposed if (_fieldControlHash != null) { _fieldControlHash = null; } if (_log != null) { _log = null; } if (_tLogic != null) { _tLogic = null; } if (_curTrans != null) { _curTrans=null; } if (_curUser != null) { _curUser=null; } if (_dynpop != null) { _dynpop = null; } //if (_environ != null) //{ // _environ = null; //} if (conGenGlobal != null) { conGenGlobal = null; } if (_CMSNotesLogic != null) { _CMSNotesLogic = null; } if (el != null) { el = null; } if (elog != null) { elog = null; } if (_mlogger != null) { _mlogger = null; } if (_mlog != null) { _mlog = null; } #endregion } disposed = true; } }

}

}

推荐答案

仅在需要处理资源时才需要实现IDisposable .通常,如果您使用实现IDisposible的类,则需要确保在使用完该类后,执行该类的Dispose方法.这可以通过使用using 语句或在try...catch...finally的finally 部分中调用Dispose来完成.否则,您应该实现IDisposable,并确保处置Disposable资源.您还需要确保在完成该类后调用Dispose 方法,否则没有意义.您可以确保doin调用了上述类的Dispose 方法.您还可以创建一些案例,在这些案例中,您管理的资源不是一次性的,但在业务应用程序中很少见. You only need to implement IDisposable if you need to dispose of resources. Generally, if you are using a class that implements IDisposible, you need to ensure that the class''s Dispose method is executed when you are finished using the class. This can be done by using the using statement, or by calling Dispose in the finally part of a try...catch...finally. Otherwise you should implement IDisposable, and ensure that the Disposable resource is disposed of. You also need to ensure that you call the Dispose method when finished with the class, otherwise there is no point. You can ensure that a class''s Dispose method is called by doin what was stated above. You can also create cases where you are managing resources that do not have a disposable, but that is rare in business applications.

更多推荐

我们可以/是否需要

本文发布于:2023-11-11 07:46:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577791.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我们可以

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!