C#中Dispose和Close的区别__教程 |
|
日期:2007-5-9 18:53:14 人气:228 [大 中 小] |
|
|
|
26 m_bitmap.Dispose(); 27 } 28 Marshal.FreeCoTaskMem(m_unmanagedResource); 29 m_disposed = true; 30 } 31 } 32 33 public void Close() 34 { 35 ((IDisposable)this).Dispose(); 36 } 37 38 ~MyStream() 39 { 40 Dispose(false); 41 } 42 43 private IntPtr m_unmanagedResource; // Unmanaged resource 44 private Bitmap m_bitmap; // IDisposable managed resources 45 private bool m_disposed; 46 47 #endregion 48 } 49 50 class MyDerivedStream : MyStream 51 { 52 public MyDerivedStream() 53 { 54 m_anotherMemory = Marshal.AllocCoTaskMem(20); 55 m_anotherImage = new Bitmap(24, 24); 56 } 57 58 protected override void Dispose(bool isDisposing) 59 { 60 if (!m_disposed) 61 { 62 if (isDisposing) |
|
出处:本站原创 作者:佚名 |
|
|