在以下代码段中关闭应用程序后,我得到一个InvalidComObjectException:
class MyExcelManager { myExelAppInstance = new Excel.Application(); // finalizer ~MyExcelManager() { myExelAppInstance.Quit(); // InvalidComObjectException thrown here myExelAppInstance = null; } }
当所有未完成的接口被释放时,Excel已经自动退出。这是由RCWs的终结器完成的。别帮忙。如果你想帮忙,那么就这样写:
class MyExcelManager : IDisposable { void Dispose() { myExelAppInstance.Quit(); } }