【问题标题】:COM exception was unhandled in c#在 C# 中未处理 COM 异常
【发布时间】:2013-09-11 15:05:41
【问题描述】:

我正在尝试使用以下方法获取自动化元素:

var automationElement = AutomationElement.FromPoint(location);

我得到了错误。

COM 异常未处理: 由于应用程序正在调度输入同步调用,因此无法进行传出调用。 (Exception from HRESULT: 0x8001010D (RPC_E_CANTCALLOUT_ININPUTSYNCCALL))

谁能帮我解决这个问题.....

【问题讨论】:

标签: c#


【解决方案1】:

这很可能是线程问题。如果您的程序试图在自己的用户界面中查找元素,则需要在单独的线程中进行。试试这个:

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

【讨论】:

  • 可以使用任务代替线程:Task.Factory.StartNew(() => {automationElement = AutomationElement.FromPoint(location); }).Wait();
【解决方案2】:

它第一次工作,但之后它不工作......

我已经使用鼠标钩在鼠标点击时获取对象的属性。这是代码。

    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";
    }

第一次点击它给出值,但在下一次点击它给出空白值,即使元素不为空。

可能有什么问题?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多