Error closing Word doc: “The message filter indicated that the application is busy.”

泪湿孤枕 提交于 2019-12-07 08:42:24

问题


I'm using Microsoft Interop to save a Word Doc as an HTML file, and I'm getting this error when I try to close the document:

The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))

Here's my code:

// word interop setting
object visible = true;
object readOnly = true;
object missing = Type.Missing;
object saveChanges = true;
object htmlFile = (object)Server.MapPath(@"worddoc.html");
object fileType = 
  (object)Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML;       

// open document
Microsoft.Office.Interop.Word.Application wordApp =
  new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document wordDoc =
  wordApp.Documents.Open(ref url, ref missing, ref readOnly, ref missing,
       ref missing, ref missing, ref missing, ref missing, ref missing,
       ref missing, ref  missing, ref  visible, ref missing, ref missing,
       ref missing, ref missing);

try
{                           
    // save the file                 
    wordDoc.SaveAs(ref htmlFile, ref fileType, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing);
}
catch (System.Exception ex)
{
    saveChanges = false;
}
finally
{
    wordDoc.Close(ref saveChanges, ref missing, ref missing); // ERROR HERE
    wordApp.Quit(ref saveChanges, ref missing, ref missing);
    wordDoc = null;
    wordApp = null;
}

Anyone know what I'm doing wrong?


回答1:


There isn't anything wrong with your code. The problem is you are running it in an unsupported configuration, and the behaviour of office is undefined in this situation (running under asp.net)

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

For more info:

http://support.microsoft.com/kb/257757

You can however use the VSTO server document class to work with office documents without starting Office.



来源:https://stackoverflow.com/questions/13995255/error-closing-word-doc-the-message-filter-indicated-that-the-application-is-bu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!