[英]COM exception was unhandled in c#
我正在尝试使用以下方法获取自动化元素:
var automationElement = AutomationElement.FromPoint(location);
而且我得到了错误。
未处理COM异常:由于应用程序正在调度输入同步调用,因此无法进行传出调用。 (Exception from HRESULT: 0x8001010D (RPC_E_CANTCALLOUT_ININPUTSYNCCALL))
谁能帮我这个忙.....
这很可能是线程问题。 如果您的程序试图在其自己的用户界面中查找元素,则需要在单独的线程中进行操作。 试试看:
var automationElement;
Thread thread = new Thread(() =>
{
automationElement = AutomationElement.FromPoint(location);
});
thread.Start();
thread.Join();
// now automationElemnt is set
它是第一次工作,但是之后就不工作了。
我已经使用mousehook获取鼠标单击时对象的属性。 这是代码。
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";
}
第一次单击将给出值,但在下次单击时将给出空白值,即使element不为null。
有什么问题吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.