1

私が実行しているコードは次のとおりです。

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 手順を台無しにしていますか?

4

1 に答える 1

0

ここでワークアウトがあります。実行中のプロセスを見つけて、コードで強制終了できます。

コード:

 Process[] pros = Process.GetProcesses();
  for (int i = 0; i < pros.Count(); i++)
     {
       if (pros[i].ProcessName.ToLower().Contains("powerpnt"))
            {
              pros[i].Kill();
            }
     }
于 2013-06-11T06:54:48.680 に答える