【发布时间】:2014-09-04 13:56:44
【问题描述】:
我正在使用多线程 WPF 应用程序 (.NET Framework 4) 中的互操作库将大量 MS Word 文档转换为 PDF。我在某些 word 文档中收到以下错误:
它会阻止当前线程,直到我在对话框上单击“确定”,然后继续转换,转换后的 PDF 也可以正常工作。
这只发生在某些文档上。我在多台计算机上运行该应用程序,这也发生在其他计算机上。
以下是我的转换代码:
var wordApplication = new Microsoft.Office.Interop.Word.Application();
// Opening the word document
var wordDocument = wordApplication.Documents.Open(tempFile, false, true, false, NoEncodingDialog: false);
// Exporting the document to the PDF
wordDocument.ExportAsFixedFormat(pdfPath, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);
// Closing the document and the application.
((Microsoft.Office.Interop.Word._Document)wordDocument).Close(false);
((Microsoft.Office.Interop.Word._Application)wordApplication).Quit(false);
Marshal.ReleaseComObject(wordDocument);
Marshal.ReleaseComObject(wordApplication);
wordDocument = null;
wordApplication = null;
有人知道是什么原因造成的吗?或者我是否可以从我的应用程序中关闭此对话框?
谢谢
【问题讨论】:
-
是的,建议的修复方法之一对我有用。非常感谢。
标签: c# wpf multithreading ms-word office-interop