System.Windows.Automation 非常慢
System.Windows.Automation is extremely slow
System.Windows.Automation 非常慢。
我执行:
element.FindAll(TreeScope.Children, Condition.TrueCondition);
在非常快的计算机上,仅获取 30 个子元素可能需要 1000 毫秒。
我什至看到它在 QT 应用程序中获取树的子元素时永远挂起。
这是一个已知问题吗?
在谷歌搜索了很多之后,我找不到任何有用的答案。
System.Windows.Automation
非常 慢 。
System.Windows.Automation
充满了 错误 。它可能不会 return 一个 AutomationElement 的所有子元素,这是一个非常严重的错误。
除此之外,该实现不是线程安全的。
System.Windows.Automation
已弃用。不要使用它!
在 MSDN 中,您会发现以下注释:
UI Automation was first available in Windows XP as part of the
Microsoft .NET Framework. Although an unmanaged C++ API was also
published at that time, the usefulness of client functions was limited
because of interoperability issues. For Windows 7, the API has been
rewritten in the Component Object Model (COM).
Although the library functions introduced in the earlier version of
UI Automation are still documented, they should not be used in new
applications.
性能下降的解决方案是使用新的 IUIAutomationElement COM 接口而不是旧的 System.Windows.Automation C# 接口。之后代码将运行 快如闪电!
除此之外,新界面提供了更多的模式,并且 Microsoft 正在不断扩展它。在 Windows 10 SDK(UIAutomationClient.h 和 UIAutomationCore.h)中添加了几个模式和属性,它们在 .NET 自动化框架中不可用。
以下模式在 UIAutomation 的 COM 版本中可用,但在 System.Windows.Automation 中不存在:
- IUIAutomationLegacyIAccessiblePattern
- IUIAutomationObjectModelPattern
- IUIAutomationAnnotationPattern
- IUIAutomationTextPattern2
- IUIAutomationStylesPattern
- IUIAutomationSpreadsheetPattern
- IUIAutomationSpreadsheetItemPattern
- IUIAutomationTransformPattern2
- IUIAutomationTextChildPattern
- IUIAutomationDragPattern
- IUIAutomationDropTargetPattern
- IUIAutomationTextEditPattern
- IUIAutomationCustomNavigationPattern
另外还添加了以下控件类型:
- 应用栏
- 语义缩放
此外还添加了以下元素:
- IUIAutomationElement2
- IUIAutomationElement3
- IUIAutomationElement4
关于 bugs 的问题:新的 COM UIAutomation Framework 设计得非常好,我在 client side 上找不到 bugs与 System.Windows.Automation
相比,这是一个很大的进步。但是框架的 服务器端 缺少一些功能甚至错误。在服务器端,每个 GUI 框架都必须实现一个 UIAutomation 提供程序(参见 MSDN: Interfaces for Providers)。因此,这些问题因您自动化的应用程序类型而异,因为每个 GUI 框架都有其自身的问题:
本机 Windows GUI 功能缺失:许多控件没有实现它们应该实现的模式。例如,本机工具栏中的 SplitButton 应该实现 Invoke
模式来单击按钮和 ExpandCollapse
模式来打开 drop-down 菜单。但是缺少 ExpandCollapse
模式,这使得使用 SplitButtons 变得困难。如果您通过 IUIAutomation->ElementFromPoint()
获得一个 Toolbar SplitButton 然后询问它的父元素,您将得到一个残缺的元素。而Pager控件根本无法自动化
此外,在 WPF 应用程序 中,Microsoft 实现了一些有缺陷的控件:例如,如果您有一个 Calendar 控件,您会看到两个顶部的按钮切换到 next/previous 月份。如果您在这些按钮上执行 Invoke
模式,您将收到 UIA_E_NOTSUPPORTED
错误。但这不是框架客户端的错误,因为对于其他按钮,Invoke
模式可以正常工作。这是 WPF 自动化服务器中的错误。如果您使用 WPF RichTextBox 测试 IUIAutomationTextRange
,您会发现有几个命令没有执行:Select()
和 ScrollIntoView()
什么都不做。
对于.NET Forms 应用程序 Microsoft 没有做出太多努力来支持它们。 .NET Calendar 控件根本无法自动化。整个控件甚至不被识别为日历。它的 ControlType "Pane" 没有子元素。这同样适用于 DateTimePicker。对于像 DataGrid 和 PropertyGrid 这样的复杂控件,唯一实现的模式是 LegacyIAccessible
,这是一个糟糕的支持。这些控件至少应实现 Table
、Grid
和 ScrollItem
模式。
另外 Internet Explorer 无法自动化,因为可见区域之外的元素由于缺少坐标而无法自动滚动到视图中。 (边界被 return 编辑为空矩形)并且未实现 ScrollItem
模式。 (是的,我知道 Internet Explorer 在 Windows 10 中已被 Edge 取代,但 UIAutomation 框架自 Windows 7 以来就存在,并且微软这些年来没有在 Internet Explorer 中实现有用的自动化支持)
我什至看到自动化应用程序完全 崩溃 。例如 Visual Studio 和 TotalCommander 如果你在某个控件上执行某些自动化命令就会崩溃。这里 - 再一次 - 错误在于框架的服务器端实现。
总结: 我们有一个很棒的框架,但用处有限。开发新的 UIAutomation 框架的微软团队做得很好,但微软的其他领域(原生 GUI、WPF、.NET 和 Internet Explorer 团队)并不支持这个框架。这是非常可悲的,因为只需要付出很小的努力就可以提供更好的功能。但似乎最开始使用UIAutomation的用户(残障人士)并不是一个有利可图的市场。
System.Windows.Automation 非常慢。
我执行:
element.FindAll(TreeScope.Children, Condition.TrueCondition);
在非常快的计算机上,仅获取 30 个子元素可能需要 1000 毫秒。
我什至看到它在 QT 应用程序中获取树的子元素时永远挂起。
这是一个已知问题吗? 在谷歌搜索了很多之后,我找不到任何有用的答案。
System.Windows.Automation
非常 慢 。
System.Windows.Automation
充满了 错误 。它可能不会 return 一个 AutomationElement 的所有子元素,这是一个非常严重的错误。
除此之外,该实现不是线程安全的。
System.Windows.Automation
已弃用。不要使用它!
在 MSDN 中,您会发现以下注释:
UI Automation was first available in Windows XP as part of the Microsoft .NET Framework. Although an unmanaged C++ API was also published at that time, the usefulness of client functions was limited because of interoperability issues. For Windows 7, the API has been rewritten in the Component Object Model (COM). Although the library functions introduced in the earlier version of UI Automation are still documented, they should not be used in new applications.
性能下降的解决方案是使用新的 IUIAutomationElement COM 接口而不是旧的 System.Windows.Automation C# 接口。之后代码将运行 快如闪电!
除此之外,新界面提供了更多的模式,并且 Microsoft 正在不断扩展它。在 Windows 10 SDK(UIAutomationClient.h 和 UIAutomationCore.h)中添加了几个模式和属性,它们在 .NET 自动化框架中不可用。
以下模式在 UIAutomation 的 COM 版本中可用,但在 System.Windows.Automation 中不存在:
- IUIAutomationLegacyIAccessiblePattern
- IUIAutomationObjectModelPattern
- IUIAutomationAnnotationPattern
- IUIAutomationTextPattern2
- IUIAutomationStylesPattern
- IUIAutomationSpreadsheetPattern
- IUIAutomationSpreadsheetItemPattern
- IUIAutomationTransformPattern2
- IUIAutomationTextChildPattern
- IUIAutomationDragPattern
- IUIAutomationDropTargetPattern
- IUIAutomationTextEditPattern
- IUIAutomationCustomNavigationPattern
另外还添加了以下控件类型:
- 应用栏
- 语义缩放
此外还添加了以下元素:
- IUIAutomationElement2
- IUIAutomationElement3
- IUIAutomationElement4
关于 bugs 的问题:新的 COM UIAutomation Framework 设计得非常好,我在 client side 上找不到 bugs与 System.Windows.Automation
相比,这是一个很大的进步。但是框架的 服务器端 缺少一些功能甚至错误。在服务器端,每个 GUI 框架都必须实现一个 UIAutomation 提供程序(参见 MSDN: Interfaces for Providers)。因此,这些问题因您自动化的应用程序类型而异,因为每个 GUI 框架都有其自身的问题:
本机 Windows GUI 功能缺失:许多控件没有实现它们应该实现的模式。例如,本机工具栏中的 SplitButton 应该实现 Invoke
模式来单击按钮和 ExpandCollapse
模式来打开 drop-down 菜单。但是缺少 ExpandCollapse
模式,这使得使用 SplitButtons 变得困难。如果您通过 IUIAutomation->ElementFromPoint()
获得一个 Toolbar SplitButton 然后询问它的父元素,您将得到一个残缺的元素。而Pager控件根本无法自动化
此外,在 WPF 应用程序 中,Microsoft 实现了一些有缺陷的控件:例如,如果您有一个 Calendar 控件,您会看到两个顶部的按钮切换到 next/previous 月份。如果您在这些按钮上执行 Invoke
模式,您将收到 UIA_E_NOTSUPPORTED
错误。但这不是框架客户端的错误,因为对于其他按钮,Invoke
模式可以正常工作。这是 WPF 自动化服务器中的错误。如果您使用 WPF RichTextBox 测试 IUIAutomationTextRange
,您会发现有几个命令没有执行:Select()
和 ScrollIntoView()
什么都不做。
对于.NET Forms 应用程序 Microsoft 没有做出太多努力来支持它们。 .NET Calendar 控件根本无法自动化。整个控件甚至不被识别为日历。它的 ControlType "Pane" 没有子元素。这同样适用于 DateTimePicker。对于像 DataGrid 和 PropertyGrid 这样的复杂控件,唯一实现的模式是 LegacyIAccessible
,这是一个糟糕的支持。这些控件至少应实现 Table
、Grid
和 ScrollItem
模式。
另外 Internet Explorer 无法自动化,因为可见区域之外的元素由于缺少坐标而无法自动滚动到视图中。 (边界被 return 编辑为空矩形)并且未实现 ScrollItem
模式。 (是的,我知道 Internet Explorer 在 Windows 10 中已被 Edge 取代,但 UIAutomation 框架自 Windows 7 以来就存在,并且微软这些年来没有在 Internet Explorer 中实现有用的自动化支持)
我什至看到自动化应用程序完全 崩溃 。例如 Visual Studio 和 TotalCommander 如果你在某个控件上执行某些自动化命令就会崩溃。这里 - 再一次 - 错误在于框架的服务器端实现。
总结: 我们有一个很棒的框架,但用处有限。开发新的 UIAutomation 框架的微软团队做得很好,但微软的其他领域(原生 GUI、WPF、.NET 和 Internet Explorer 团队)并不支持这个框架。这是非常可悲的,因为只需要付出很小的努力就可以提供更好的功能。但似乎最开始使用UIAutomation的用户(残障人士)并不是一个有利可图的市场。