2013-09-24 38 views
0

我喂多個文檔到下面的方法,看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); 
} 
+0

魯克,你搖滾。我完全按照你所描述的每次完美的執行。謝謝! –

回答

0

我對AV有類似的問題。

你需要把它變成一個嘗試捕捉,並在漁獲物中,添加一個睡眠(),然後再試一次。

我最後不得不制定出文件有多大,以確定睡眠應(基於掃描了多長時間回事大約比例所花費的掃描時間)有多長。

希望這是足以讓你去不去?

+0

您能否爲您提出的解決方案顯示代碼? – ecoe