我有一个使用
Thread类的类:
class A { public Thread thread { get; set; } }
我应该实现IDisposable并将Thread属性设置为null吗?
class A : IDisposable { public Thread Thread { get; set; } protected bool Disposed { get; set; } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (!this.Disposed) { if (disposing) { if (Thread != null) Thread = null; } Disposed = true; } } }
或不?
为什么?