这是我正在运行的代码:
MsoTriState readOnly = MsoTriState.msoTrue;
MsoTriState untitled = MsoTriState.msoFalse;
MsoTriState withWindow = MsoTriState.msoFalse;
string filePath; //some file path to a pptx
ppt.Application app = null;
ppt.Presentations presentations = null;
ppt.Presentation presentation = null;
app = new ppt.Application();
presentations = app.Presentations;
presentation = presentations.Open(filePath, readOnly, untitled, withWindow);
System.Runtime.InteropServices.Marshal.ReleaseComObject(presentation);
presentation = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(presentations);
presentations = null;
app.Quit(); //HANGING HERE
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
app = null;
这是一个非常基本的代码,可以打开一个 PowerPoint 应用程序,然后将其关闭。但是,由于某种原因,它正在挂起app.Quit()
电话。另外,我不知道为什么,但是如果我注释掉 ComRelease 演示文稿的行,它就不会挂起。另一种技巧是在调用 app.Quit 之前使 app.Visible = msoTrue。
有谁知道这里发生了什么?我搞砸了我的 ComRelease 程序吗?