我有一个使用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;
}
}
}
或不?
为什么?