c#interop winword.exe不';不要退出!

c#interop winword.exe不';不要退出!,c#,interop,quit,C#,Interop,Quit,我将多个文档输入到下面的方法中,并在15台运行WinXP 32位到Win8 64位(Office 2000以后版本)的不同PC上看到winword.exe的预期结果。在一台运行Trend的Antivirus的噩梦PC上,winword.exe(总是,每次)会以“正在使用的文件”异常中断循环(关闭Trends可使其再次工作)。有什么保持趋势的想法吗 void loop() { Microsoft.Office.Interop.Word._Application app = new Microsof

我将多个文档输入到下面的方法中,并在15台运行WinXP 32位到Win8 64位(Office 2000以后版本)的不同PC上看到winword.exe的预期结果。在一台运行Trend的Antivirus的噩梦PC上,winword.exe(总是,每次)会以“正在使用的文件”异常中断循环(关闭Trends可使其再次工作)。有什么保持趋势的想法吗

void loop()
{
Microsoft.Office.Interop.Word._Application app = new Microsoft.Office.Interop.Word.Application();
app.Visible = false; app.ScreenUpdating = false; app.DisplayAlerts = WdAlertLevel.wdAlertsNone;

Microsoft.Office.Interop.Word._Document doc = app.Documents.Open(FilePath, false, true, false);
doc.Activate(); doc.DisableFeatures = true;

doc.ExportAsFixedFormat(newFileName, WdExportFormat.wdExportFormatPDF, false,WdExportOptimizeFor.wdExportOptimizeForOnScreen, WdExportRange.wdExportCurrentPage, 1, 1, WdExportItem.wdExportDocumentWithMarkup, false, false, WdExportCreateBookmarks.wdExportCreateNoBookmarks, true, false, true, Type.Missing);

((Microsoft.Office.Interop.Word._Document)doc).Close(WdSaveOptions.wdDoNotSaveChanges);
Marshal.ReleaseComObject(doc);
Marshal.FinalReleaseComObject(doc);

((Microsoft.Office.Interop.Word._Application)app).Quit(WdSaveOptions.wdDoNotSaveChanges);
Marshal.ReleaseComObject(app);
Marshal.FinalReleaseComObject(app);

GC.GetTotalMemory(false);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.GetTotalMemory(true);
}

我的AV也有类似的问题

您需要将其放入try catch中,在catch中添加Sleep(),然后重试

最后,我不得不计算出文件的大小,以确定睡眠时间(根据扫描持续的时间与扫描所用的时间成正比)


希望这足够让你走了?

车,你太棒了。我每次都像你说的那样完美地执行。非常感谢。您能为您提出的解决方案显示代码吗?