none
MS-WORD AUTOMATION ERROR : "The message filter indicated that the application is busy."

    Question

  • Hi,

    I am getting this error while creating word application instance from vb.net/c# for web applications.

    Dcomcnfg is configured as per microsoft instructions for the same for the permissions.

    But still I am getting error:

     {"The message filter indicated that the application is busy." }

    If any one can provide the resolution for the same that will be a great help.

    Thanks and Regards,

    Ashish

    Complete Exception detail as below:

    - exc {"The message filter indicated that the application is busy." } System.Exception
    + [System.Runtime.InteropServices.COMException] {System.Runtime.InteropServices.COMException} System.Runtime.InteropServices.COMException
     System.Object {System.Runtime.InteropServices.COMException} System.Object
     _className null string
     _COMPlusExceptionCode -532459699 int
     _exceptionMethod <undefined value> System.Reflection.MethodBase
     _exceptionMethodString null string
     _helpURL null string
     _HResult -2147417846 int
     _innerException { } System.Exception
     _message "The message filter indicated that the application is busy." string
     _remoteStackIndex 0 int
     _remoteStackTraceString null string
     _source null string
    + _stackTrace {System.Array} System.Object
     _stackTraceString null string
     _xcode -532459699 int
     _xptrs 0 int
     HelpLink null string
     HResult -2147417846 int
     InnerException { } System.Exception
     Message "The message filter indicated that the application is busy." string
     Source "WordApplication" string
     StackTrace "   at WordApplication.CCWordApp..ctor() in d:\\wordapplication\\ccwordapp.cs:line 21\r\n   at WordApplication.CreateNewDoc.Button2_Click(Object sender, EventArgs e) in d:\\wordapplication\\createnewdoc.aspx.cs:line 71" string
    + TargetSite {System.Reflection.RuntimeConstructorInfo} System.Reflection.MethodBase


    Monday, September 11, 2006 1:39 PM

Answers

  • Hi,

    At issue is the fact that the Word objects you are calling into do not support multiple threading.  Since they are exposed to arbitrary clients via COM, the possibility exists that multiple threads could attempt to simultaneously execute code within the object.  To prevent this from happening, will serialize all incoming calls by queuing them up and only allowing one call at a time to execute.  This is done by packaging up the details of each call and posting a message to Word.  When Word processes, the message, the call will execute on Word's own main thread.  The problem with this approach is that if Word is busy doing something else when the call comes in, the caller will have to wait.  In addition, Word might not be in a state where it is willing to service automation calls.  To avoid the possibility of deadlocks, COM introduced the IMessageFilter interface.  Through this interface the server has the opportunity to explicitly reject calls (and COM may also reject calls implicitly).  When this happens, the client's IMessageFilter::RetryRejectedCall will be called and the client will have the opportunity to decide what to do.  Options include continuing to wait, cancelling the call, or displaying the OLEUIBUSY dialog (which gives the user the opportunity to switch to the server--where they may be able take some action to "unbusy" the server). 

    If you don't register a MessageFilter yourself (by calling CoRegisterMessageFilter), you will get default behavior which will be to fail the call if it gets rejected.  .Net converts the failure HRESULT to an exception.  To deal with the possibility of the server being busy when you try to call, you need to implement IMessageFilter::RetryRejectedCall in your client code and also register the message filter.  In most cases, you will just need to wait for a few seconds and then retry the call--generally that will be sufficient time to enable Word to finish whatever it is doing so it can handle your call.  However, if the instance of Word that you are controlling could possibly visible, you might want to add additional logic to display the OLEUIBUSY dialog after some amount of time has passed to notify the user that you are waiting on Word to do something and give them the opportunity to help the process.  For example, as Misha mentions, Word will reject all incoming calls if a modal dialog box is up.  Therefore, in that situation, you would be blocked indefinitely until the dialog is dismissed.

    Hopefully this makes sense.  As Cindy says, this really wasn't the right place to post this question, but I wanted to answer it because quite a few VSTO folks encounter this issue as well.

    Sincerely,

    Geoff Darst

    Microsoft VSTO Team

    Tuesday, September 12, 2006 6:42 PM
    Answerer
  • Does your Word app display a message box? Word will not accept external communication when it is showing a modal dialog.
    Monday, September 11, 2006 4:01 PM
  • Hi arai03

    Are you familiar with this article

    http://support.microsoft.com/kb/257757/en-us

    Please note that this forum is for questions concerning VSTO technolgy. Since you're trying to automate an Office application, you should pursue this topic in the office.developer.automation newsgroup, where you may find others who've worked through the same issues.

    http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.office.developer.automation&lang=en&cr=US

    Tuesday, September 12, 2006 7:02 AM
    Moderator

All replies

  • This forum is targeted to questions concerning the VSTO technology. You apparently aren't using VSTO, but it's not clear what you are trying to do, making it difficult to point you to a an appropriate place to present your problem. Perhaps the answer in this thread applies?

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=714050&SiteID=1

    Monday, September 11, 2006 1:52 PM
    Moderator
  • Does your Word app display a message box? Word will not accept external communication when it is showing a modal dialog.
    Monday, September 11, 2006 4:01 PM
  • no. I am calling a method from asp.net page and my service layer is serving for that to generate a word document on the fly at the server.

    For that I configured "Dcom" on the server.

    and getting this error while trying to add some template file to the wordApp.Document object using

    WordApp.Document.Add(template)

    Some time it throws the error at line

    docs.Unprotect("password")

    Pls send me you inputs

     

    Public Class WordDoc

        Dim WordApp As word.ApplicationClass

        Private Function InitializeWord() As Boolean
            ' This function is used to initialize the global Application and
            ' NameSpace variables.

            'On Error GoTo Init_Err

            Try
                WordApp = New word.ApplicationClass        ' Application object.
                InitializeWord = True
            Catch ex As Exception
                'System.Runtime.InteropServices.Marshal.ReleaseComObject(WordApp)
                InitializeWord = False
                Throw New Exception(ex.Message, ex.InnerException)
            End Try

            'Init_End:
            '       Exit Function
            'Init_Err:
            'InitializeWord = False
            'Resume Init_End
        End Function

        Public Function Create_Doc_From_Template(ByVal template As String) As word.Document
            Try
                Create_Doc_From_Template = WordApp.Documents.Add(template)
            Catch e As Exception
                Dim err As DataLayer.ErrLog = New DataLayer.ErrLog("Greensheet.BusinessLayer.WordDoc")
                err.log("Greensheet.BusinessLayer.WordDoc", e.Message & " : " & template)
                GC.Collect()
            End Try
        End Function

        Public Function Create_888Conf(ByVal strPath As String, ByVal strFileName As String, ByVal strConfNo As String, _
                ByVal strTo As String, ByVal strCom As String, ByVal strGuestName As String, ByVal strLoc As String, ByVal strMIDate As String, _
                ByVal strITVDate As String, ByVal strRate As String, ByVal strDay As String, ByVal strRef As String, _
                ByVal strUserName As String, ByVal strUserEmail As String, ByVal strAddress As String, _
                ByVal strPhone As String, ByVal nAptSize As Integer, ByVal nCC As Integer, ByVal strOtherSize As String, _
                ByVal strOtherPay As String, ByVal nDay As Integer, ByVal strComment As String) As Boolean
            If WordApp Is Nothing Then
                InitializeWord()
            End If
            Dim oDoc As word.Document
            Dim oFF As word.FormFields
            Try
                oDoc = Create_Doc_From_Template(ConfigurationSettings.AppSettings.Get("888ConfTemplate"))
                oDoc.Unprotect("red")
                oFF = oDoc.FormFields
                Dim temp As word.Range
                temp = oFF.Item("Text14").Range
                temp.InsertBefore(strConfNo)
                oFF.Item("Text14").Delete()

                oFF.Item("Text2").Range.Text = strTo
                oFF.Item("Company").Range.Text = strCom
                oFF.Item("Comment").Range.Text = strComment
                oFF.Item("Text3").Range.Text = strGuestName
                oFF.Item("Text4").Range.Text = strLoc
                '/////////////////////////////////////////////////////////////////////
                '/ Fix for bug no 282
                '/ Date Changed 2006-03-14
                Dim sOutput As String
                sOutput = ""
                If Not strMIDate Is Nothing Then
                    If strMIDate.Trim().Length() > 0 Then
                        sOutput = Format(CType(strMIDate, Date), "MMMM dd,yyyy")
                    End If
                End If
                oFF.Item("Text5").Range.Text = sOutput

                sOutput = ""
                If Not strITVDate Is Nothing Then
                    If strITVDate.Trim().Length() > 0 Then
                        sOutput = Format(CType(strITVDate, Date), "MMMM dd,yyyy")
                    End If
                End If

                oFF.Item("Text6").Range.Text = sOutput
                sOutput = Nothing
                'Orginal code
                'oFF.Item("Text5").Range.Text = strMIDate
                'oFF.Item("Text6").Range.Text = strITVDate
                '/End of change
                '/////////////////////////////////////////////////////////////////////
                oFF.Item("Text18").Range.Text = strRate

                'oFF.Item("Text12").Range.Text = strDay ' remove from doc
                oFF.Item("Text13").Range.Text = strRef
                oFF.Item("Text8").Range.Text = strUserName
                oFF.Item("Text15").Range.Text = strUserEmail
                oFF.Item("Text11").Range.Text = strAddress
                oFF.Item("Text9").Range.Text = strPhone.Substring(0, 3)
                oFF.Item("Text10").Range.Text = strPhone.Substring(4, 3)
                oFF.Item("Text17").Range.Text = strPhone.Substring(8, 4)

                oFF.Item("check6").CheckBox.Value = (nCC = 1)
                oFF.Item("check7").CheckBox.Value = (nCC = 2)
                oFF.Item("check8").CheckBox.Value = (nCC = 3)
                oFF.Item("check9").CheckBox.Value = (nCC = 0)
                oFF.Item("check10").CheckBox.Value = (nCC = 4)
                oFF.Item("check6").Enabled = False
                oFF.Item("check7").Enabled = False
                oFF.Item("check8").Enabled = False
                oFF.Item("check9").Enabled = False
                oFF.Item("check10").Enabled = False
                oFF.Item("Text19").Range.Text = strOtherPay


                oFF.Item("check1").CheckBox.Value = (nAptSize = 0)
                oFF.Item("check2").CheckBox.Value = (nAptSize = 1)
                oFF.Item("check3").CheckBox.Value = (nAptSize = 2)
                oFF.Item("check4").CheckBox.Value = (nAptSize = 3)
                oFF.Item("check5").CheckBox.Value = (nAptSize = 4)
                oFF.Item("Text16").Range.Text = strOtherSize
                oFF.Item("check1").Enabled = False
                oFF.Item("check2").Enabled = False
                oFF.Item("check3").Enabled = False
                oFF.Item("check4").Enabled = False
                oFF.Item("check5").Enabled = False

                If nDay = 0 Then
                    oFF.Item("Dropdown1").Result = "Daily"
                Else : oFF.Item("Dropdown1").Result = "Nightly"
                End If
                oFF.Item("Dropdown1").Enabled = False

                oDoc.Protect(word.WdProtectionType.wdAllowOnlyFormFields, True, "red")
                oDoc.SaveAs(strPath & strFileName)
                oDoc.Close(False)
                oDoc = Nothing
                WordApp.Documents.Close()
                Create_888Conf = True
            Catch e As Exception
                Dim err As DataLayer.ErrLog = New DataLayer.ErrLog("Greensheet.BusinessLayer.WordDoc")
                err.log("Greensheet.BusinessLayer.WordDoc.Create_888Conf", e.Message & " path: " & strPath)
                GC.Collect()
                Create_888Conf = False
                'Finally
                '    If WordApp.Documents.Count > 0 Then
                '        WordApp.Documents.Close(False)
                '    End If
                '    WordApp.Quit()
                '    WordApp = Nothing
                'End Try
            Finally
                If WordApp.Documents.Count > 0 Then
                    WordApp.Documents.Close(False)
                End If
                WordApp.Quit()
                System.Runtime.InteropServices.Marshal.ReleaseComObject(WordApp)
                WordApp = Nothing
                System.GC.Collect()
            End Try
        End Function

    End Class

    • Proposed as answer by gotoyuzo Friday, April 01, 2011 3:29 AM
    • Unproposed as answer by gotoyuzo Friday, April 01, 2011 3:29 AM
    Tuesday, September 12, 2006 6:50 AM
  • pls refer to source code posted today.
    Tuesday, September 12, 2006 6:52 AM
  • Hi arai03

    Are you familiar with this article

    http://support.microsoft.com/kb/257757/en-us

    Please note that this forum is for questions concerning VSTO technolgy. Since you're trying to automate an Office application, you should pursue this topic in the office.developer.automation newsgroup, where you may find others who've worked through the same issues.

    http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.office.developer.automation&lang=en&cr=US

    Tuesday, September 12, 2006 7:02 AM
    Moderator
  • Hi,

    At issue is the fact that the Word objects you are calling into do not support multiple threading.  Since they are exposed to arbitrary clients via COM, the possibility exists that multiple threads could attempt to simultaneously execute code within the object.  To prevent this from happening, will serialize all incoming calls by queuing them up and only allowing one call at a time to execute.  This is done by packaging up the details of each call and posting a message to Word.  When Word processes, the message, the call will execute on Word's own main thread.  The problem with this approach is that if Word is busy doing something else when the call comes in, the caller will have to wait.  In addition, Word might not be in a state where it is willing to service automation calls.  To avoid the possibility of deadlocks, COM introduced the IMessageFilter interface.  Through this interface the server has the opportunity to explicitly reject calls (and COM may also reject calls implicitly).  When this happens, the client's IMessageFilter::RetryRejectedCall will be called and the client will have the opportunity to decide what to do.  Options include continuing to wait, cancelling the call, or displaying the OLEUIBUSY dialog (which gives the user the opportunity to switch to the server--where they may be able take some action to "unbusy" the server). 

    If you don't register a MessageFilter yourself (by calling CoRegisterMessageFilter), you will get default behavior which will be to fail the call if it gets rejected.  .Net converts the failure HRESULT to an exception.  To deal with the possibility of the server being busy when you try to call, you need to implement IMessageFilter::RetryRejectedCall in your client code and also register the message filter.  In most cases, you will just need to wait for a few seconds and then retry the call--generally that will be sufficient time to enable Word to finish whatever it is doing so it can handle your call.  However, if the instance of Word that you are controlling could possibly visible, you might want to add additional logic to display the OLEUIBUSY dialog after some amount of time has passed to notify the user that you are waiting on Word to do something and give them the opportunity to help the process.  For example, as Misha mentions, Word will reject all incoming calls if a modal dialog box is up.  Therefore, in that situation, you would be blocked indefinitely until the dialog is dismissed.

    Hopefully this makes sense.  As Cindy says, this really wasn't the right place to post this question, but I wanted to answer it because quite a few VSTO folks encounter this issue as well.

    Sincerely,

    Geoff Darst

    Microsoft VSTO Team

    Tuesday, September 12, 2006 6:42 PM
    Answerer
  • Hi Geoff,

    Thanks for your support. I think this makes sense.

    Thanks once again.

    Sincerely,

    Ashish

    Monday, September 25, 2006 5:20 AM