我正在开发一个应用程序,允许用户上传演示文稿,编辑演示文稿,然后将最终输出作为另一个PowerPoint演示文稿下载。
对于上传的不同演示文稿,我有非常不稳定的行为:
我知道服务器端自动化可能具有不稳定的行为或死锁。然而,没有任何文件确切地记录了行为的不稳定性。
这些行为(以上两种行为)是否属于同一类别,还是我在这里遗漏了什么?我怎样才能解决这些问题?
发布于 2017-12-05 16:42:42
如果您仍然需要使用Interop,那么试着释放COM对象,然后按以下所述定位终止PowerPoint实例:
public static class PowerPointInterOp
{
static PowerPoint.Application powerPointApp = null;
static Object oMissing = System.Reflection.Missing.Value;
static Object oTrue = true;
static Object oFalse = false;
static Object oCopies = 1;
public static void InitializeInstance()
{
if (powerPointApp == null)
{
powerPointApp = new PowerPoint.ApplicationClass();
}
}
public static void KillInstances()
{
try
{
Process[] processes = Process.GetProcessesByName("POWERPNT");
foreach(Process process in processes)
{
process.Kill();
}
}
catch(Exception)
{
}
}
public static void CloseInstance()
{
if (powerPointApp != null)
{
powerPointApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(powerPointApp);
powerPointApp = null;
}
}
public static PowerPoint.Presentation OpenDocument(string documentPath)
{
InitializeInstance();
PowerPoint.Presentation powerPointDoc = powerPointApp.Presentations.Open(documentPath, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
return powerPointDoc;
}
public static void CloseDocument(PowerPoint.Presentation powerPointDoc)
{
if (powerPointDoc != null)
{
powerPointDoc.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(powerPointDoc);
powerPointDoc = null;
}
}
}https://stackoverflow.com/questions/22508145
复制相似问题