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

  • Question

  • Hello All,
        I am doing some automation using DTE and MAUI (internal automation framework), but out of 20 times i got "The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))" error. I searched about this error and got some link where asked to implement IOleMessageFilter. I copied the code even though i am getting the below error. 

    Message:

     


    Actually in my automation i am making specific toolbar visible in case by default it is not visible and here i am getting error sometime. Not sure if the messagefilter is working properly. Can somebody look into the below code and see if i am doing the correct thing. Please let me know if you have any questions.
            private Toolbar GetToolbar(string name)
            {
                MessageFilter.Register();
                MauiDTE dteobj = new MauiDTE(this.app);
    
                // Below code is just to make the required toolbar visible in case by default it is not visible
                CommandBars commandBars = (CommandBars)dteobj.DTE.CommandBars;
                CommandBar commandBar = commandBars[name];
                commandBar.Visible = true;
                Toolbar toolbar = new Toolbar(this.app, name);
                if (toolbar == null)
                {
                    throw new TestException(TestResult.Failed, string.Format("Unable to get {0} toolbar",name));
                }
    
                MessageFilter.Revoke();
                return toolbar;
            }
            public class MessageFilter : IOleMessageFilter
            {
                //
                // Class containing the IOleMessageFilter
                // thread error-handling functions.
    
                // Start the filter.
                public static void Register()
                {
                    IOleMessageFilter newFilter = new MessageFilter();
                    IOleMessageFilter oldFilter = null;
                    CoRegisterMessageFilter(newFilter, out oldFilter);
                }
    
                // Done with the filter, close it.
                public static void Revoke()
                {
                    IOleMessageFilter oldFilter = null;
                    CoRegisterMessageFilter(null, out oldFilter);
                }
    
                //
                // IOleMessageFilter functions.
                // Handle incoming thread requests.
                int IOleMessageFilter.HandleInComingCall(int dwCallType,
                  System.IntPtr hTaskCaller, int dwTickCount, System.IntPtr
                  lpInterfaceInfo)
                {
                    //Return the flag SERVERCALL_ISHANDLED.
                    return 0;
                }
    
                // Thread call was rejected, so try again.
                int IOleMessageFilter.RetryRejectedCall(System.IntPtr
                  hTaskCallee, int dwTickCount, int dwRejectType)
                {
                    if (dwRejectType == 2)
                    // flag = SERVERCALL_RETRYLATER.
                    {
                        // Retry the thread call immediately if return >=0 & 
                        // <100.
                        return 99;
                    }
                    // Too busy; cancel call.
                    return -1;
                }
    
                int IOleMessageFilter.MessagePending(System.IntPtr hTaskCallee,
                  int dwTickCount, int dwPendingType)
                {
                    //Return the flag PENDINGMSG_WAITDEFPROCESS.
                    return 2;
                }
    
                // Implement the IOleMessageFilter interface.
                [DllImport("Ole32.dll")]
                private static extern int
                  CoRegisterMessageFilter(IOleMessageFilter newFilter, out 
              IOleMessageFilter oldFilter);
            }
    
            [ComImport(), Guid("00000016-0000-0000-C000-000000000046"),
            InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
            interface IOleMessageFilter
            {
                [PreserveSig]
                int HandleInComingCall(
                    int dwCallType,
                    IntPtr hTaskCaller,
                    int dwTickCount,
                    IntPtr lpInterfaceInfo);
    
                [PreserveSig]
                int RetryRejectedCall(
                    IntPtr hTaskCallee,
                    int dwTickCount,
                    int dwRejectType);
    
                [PreserveSig]
                int MessagePending(
                    IntPtr hTaskCallee,
                    int dwTickCount,
                    int dwPendingType);
            }
    The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))

    Source:

    EnvDTE

    Expected:

    (null)

    Received:

    System.Runtime.InteropServices.COMException

    File:

    Line: 0

    at EnvDTE._DTE.get_CommandBars()

    at Microsoft.SqlServer.VSDeveloper.ObjectModel.EditorHandler.GetToolbar(String name)

    at Microsoft.SqlServer.VSDeveloper.ObjectModel.EditorHandler.GetToolbarItem(String buttonName)

    Tuesday, August 11, 2009 3:23 PM

Answers

  • This is not a very good idea. You may want to read up on the CoRegisterMessageFilter API and ensure that your application is STA, and that the thread you're invoking this on has a message pump. You generally want to register a custom message filter like this at the application scope, and not in some private GetToolbar method, which could be invoked any number of times by this app. I'm not familiar with the Maui test framework, as most of the folks that peruse this forum.

    Sincerely,
    Ed Dore
    • Marked as answer by Wesley Yao Tuesday, August 18, 2009 5:29 AM
    Saturday, August 15, 2009 2:34 AM

All replies

  • Hi Nikhil,

    Does exactlly the IOleMessageFilter.RetryRejectedCall invoke and run into the condition 'dwRejectType == 2'?

    Sincerely,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, August 14, 2009 9:27 AM
  • This is not a very good idea. You may want to read up on the CoRegisterMessageFilter API and ensure that your application is STA, and that the thread you're invoking this on has a message pump. You generally want to register a custom message filter like this at the application scope, and not in some private GetToolbar method, which could be invoked any number of times by this app. I'm not familiar with the Maui test framework, as most of the folks that peruse this forum.

    Sincerely,
    Ed Dore
    • Marked as answer by Wesley Yao Tuesday, August 18, 2009 5:29 AM
    Saturday, August 15, 2009 2:34 AM