我喂多個文檔到下面的方法,看WINWORD.EXE disapear上運行32位的WinXP對Win8的64位有辦公室2000年起超過15 diferente電腦預期。在已公佈的反病毒軟件運行,WINWORD.EXE 1個噩夢PC(常亮,每次)中斷循環與異常的「文件正在使用」(打開關閉的趨勢使其重新工作)。任何保持趨勢的想法?c#interop winword.exe不退出()!
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);
}
魯克,你搖滾。我完全按照你所描述的每次完美的執行。謝謝! –