创建可以销毁的对象。
可以用using包含起来的类
Public class MyClass:IDisposable
{ private bool IsDisposed=false; public void Dispose() { Dispose(true); GC.SupressFinalize(this); } protected void Dispose(bool Diposing) { if(!IsDisposed) { if(Disposing) { //Clean Up managed resources } //Clean up unmanaged resources } IsDisposed=true; } ~MyClass() { Dispose(false); } }