我在 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
andFindFirst
are prone to this exception, which is raised when trying to find elements inWebView
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
withprivate 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
andFindAll
calls with customTreeWalker
iteration method.This will solve the problem with not being able to get page source for views with
WebView
s and not being able to find element inWebView
due to same error.
关于c# - Windows UIAutomation 有时会挂起其他应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47820560/