c# - Windows UIAutomation 有时会挂起其他应用程序

标签 c# com ui-automation microsoft-ui-automation

我在 WPF 客户端应用程序中通过 COM 接口(interface)使用 UIAutomation。有些用户有时会使用他们的特定应用程序(例如 nVidia 控制面板)。我的应用程序收到该异常:

System.Runtime.InteropServices.COMException (0x80131505): Operation timed out. (Exception from HRESULT: 0x80131505) in UIAutomationClient.IUIAutomationElement.FindAll (TreeScope scope, IUIAutomationCondition condition).

我无法在我的电脑上重现此内容。

  • 您有解决此类问题的经验吗?
  • 对于这种情况,您有什么解决方法吗?
  • 我可以以某种方式减少 COM 超时吗?也许这会解决问题

最佳答案

我找到了一些有关该问题的信息。

  • UIAutomation 仅在带有 Creator's Update ( source ) 的 Windows 10 上不稳定
  • 这是错误,已提交 here
  • NickAb 找到了解决方案:使用 TreeWalker ( source )

Both FindAll and FindFirst are prone to this exception, which is raised when trying to find elements in WebView that has loaded its data recently, exception is thrown when methods try to build cache, so it might be due to trying to iterate visual tree while it is being rebuild by another thread.

Replacing FindAll with

private IEnumerable<WiniumElement> GetChildrens()
{
    var elementNode = TreeWalker.ControlViewWalker.GetFirstChild(this.AutomationElement);

    while (elementNode != null)
    {
        yield return new WiniumElement(elementNode);
        elementNode = TreeWalker.ControlViewWalker.GetNextSibling(elementNode);
    }
}

Solves the problem. Needs further investigation. Most likely we will have to replace both FindFirst and FindAll calls with custom TreeWalker iteration method.

This will solve the problem with not being able to get page source for views with WebViews and not being able to find element in WebView due to same error.

关于c# - Windows UIAutomation 有时会挂起其他应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47820560/

相关文章:

c# - 以编程方式从基于 Claims auth 的 SharePoint 2010 站点下载文件

c# - 数据模型未显示在 HttpResponseMessage 中

c# - 工厂对象由于依赖于自身而导致 stackoverflowException

visual-studio-2010 - EnvDTE 的类型库在哪里?

c# - 是否可以从 webbrowser NavigationFailed 事件中导航?

windows - Windows Server 2008 的 FaxServer 替代品

c++ - 如何在 Windows 属性系统中创建 IconList 属性?

java - Selenium Java - 检查 Weblist 元素是否存在

java - 实现 selenium webdriver 时如何将表中的 WebElements 列表存储到列表中?

swift - 如何识别在 xcode 中运行 XCUITest 时抛出的一些随机窗口