实现IDisposable
这个问题在这里已经有了答案:
鉴于它使用明确的接口实现,我不清楚他们想要你,但你可以:
public class MyClass : IDisposable
{
private WebServiceHost m_WebServiceHost;
// Members
public void Dispose()
{
((IDisposable)m_WebServiceHost).Dispose();
}
}
我猜想他们更喜欢你只需要调用Close()
,但是我不能从文档中支持它。
像这样做:
public class MyClass : IDisposable
{
private WebServiceHost m_WebServiceHost;
// Often you have to override Dispose method
protected virtual void Dispose(Boolean disposing) {
if (disposing) {
// It looks that WebServiceHost implements IDisposable explicitly
IDisposable disp = m_WebServiceHost as IDisposable;
if (!Object.RefrenceEquals(null, disp))
disp.Dispose();
// May be useful when debugging
disp = null;
}
}
// Members
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
链接地址: http://www.djcxy.com/p/54485.html