C#使用Dispose模式实现手动对资源的释放
来源:本站原创|时间:2022-11-25|栏目:C#教程|
本文实例讲述了C#使用Dispose模式实现手动对资源的释放。分享给大家供大家参考。具体实现方法如下:
//单一类的实现 class MyClass : IDisposable { public MyClass(){} ~MyClass() { // In case the client forgets to call // Dispose , destructor will be invoked for Dispose(false); } protected virtual void Dispose(bool disposing) { if (disposing) { // Free managed objects. } // Free unmanaged objects } public void Dispose() { Dispose(true); // Ensure that the destructor is not called GC.SuppressFinalize(this); } }
希望本文所述对大家的C#程序设计有所帮助。
您可能感兴趣的文章
- 01-10C#3.0使用EventLog类写Windows 日志的方法
- 01-10C#使用windows服务开启应用程序的方法
- 01-10深入浅出23种设计模式
- 01-10c# ArrayList的使用方法小总结
- 01-10C#使用ADO.Net部件来访问Access数据库的方法
- 01-10C#使用Mutex简单实现程序单实例运行的方法
- 01-10使用Nopcommerce为商城添加满XX减XX优惠券功能
- 01-10C#中yield用法使用说明
- 01-10C#编程和Visual Studio使用技巧(下)
- 01-10C#编程和Visual Studio使用技巧(上)