哪種更正確的方式來轉發COM對象,類型1或類型2或無關緊要? (_ 文件是接口)發佈Com對象
private IHTMLDocument2 _document;
public HtmlDocument()
{
_document = new HTMLDocumentClass();
}
private void DisposeUnmanagedResources1()
{
if (_document != null)
{
Marshal.ReleaseComObject(_document);
_document = null;
}
}
private void DisposeUnmanagedResources2()
{
if (_document != null)
{
var doc = ((HTMLDocumentClass) _document);
Marshal.ReleaseComObject(doc);
doc = null;
_document = null;
}
}
'DisposeUnmanagedResources1()'似乎就足夠了。 – 2011-04-26 21:44:03