Com PowerPoint正在挂起应用程序。请退出呼叫

Com PowerPoint正在挂起应用程序。请退出呼叫,com,powerpoint,Com,Powerpoint,以下是我正在运行的代码: 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 presentati

以下是我正在运行的代码:

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()调用上。另外,我也不知道为什么,但如果我在发布演示文稿的那一行加上注释,它就挂不住了。另一种方法是在调用app.Quit之前使app.Visible=msoTrue


有人知道这里发生了什么吗?我把ComRelease程序搞砸了吗?

我这里有一个训练给你。你可以找到正在运行的过程,然后通过代码终止它

代码:

 Process[] pros = Process.GetProcesses();
  for (int i = 0; i < pros.Count(); i++)
     {
       if (pros[i].ProcessName.ToLower().Contains("powerpnt"))
            {
              pros[i].Kill();
            }
     }
Process[]pros=Process.getprocesss();
for(int i=0;i
抱歉,我无法提供解决方案,只能确认我可以重现该行为。COM参考资料对我来说很好。在我的机器上,退出会阻塞CPU,因此PowerPoint似乎挂在无限循环中。我看不出这是怎么由未发布的引用引起的。忘了我刚才说的吧。我停用了一个加载项,现在它可以工作了。也许你也有类似的经历?哦,我想你可能是对的。禁用我的一个加载项似乎可以解决这个悬而未决的问题。好主意!