COM exception was unhandled in c#

2

I am trying to get Automation Element using:

var automationElement = AutomationElement.FromPoint(location);

And I am geting error.

COM exception was unhandled: An outgoing call cannot be made since the application is dispatching an input-synchronous call. (Exception from HRESULT: 0x8001010D (RPC_E_CANTCALLOUT_ININPUTSYNCCALL))

Can any one help me out with this please.....

c#
asked on Stack Overflow Sep 7, 2013 by Ashka • edited Sep 7, 2013 by Rahul Tripathi

2 Answers

5

It is most likely a threading issue. If your program is trying to find an element in its own user interface you need do it in a separate thread. Give this a try:

var automationElement;
Thread thread = new Thread(() =>
{
    automationElement = AutomationElement.FromPoint(location);
});
thread.Start();
thread.Join();
// now automationElemnt is set
1

It is working for 1st time but after that it is not working....

I have use mousehook to get property of object on mouse click. Here is code.

    private  AutomationElement GetAutomationElementFromPoint(Point location)
    {


        AutomationElement automationElement =null;

        Thread thread = new Thread(() =>
        {
            automationElement = AutomationElement.FromPoint(location);
        });

        thread.Start();
        thread.Join();
        return automationElement;
    }

     private void mouseHook_MouseClick(object sender, MouseEventArgs e)
    {
        AutomationElement element = GetAutomationElementFromPoint(new System.Windows.Point(e.X, e.Y));

        //Thread.Sleep(900);
        if (element != null)
        {

           textBox1.Text =  "Name: " + element.Current.Name + " ID: " + element.Current.AutomationId + " Type: " + element.Current.LocalizedControlType;
        }
        else
           textBox1.Text = "Not found";
    }

On 1st click it is giving values, but on next click it gives blank values even if element is not null.

What can be problem?

answered on Stack Overflow Sep 11, 2013 by Ashka

User contributions licensed under CC BY-SA 3.0