Jor*_*dan 5 c# ui-automation microsoft-ui-automation
我们一直在使用 MS UIA 框架,并注意到在 Windows 10 / .NET 4.6 中查找对象集合时出现的明显放缓。
在 Windows 10 / .NET 4.6 机器上测试 AutomationElement.FindAll() 时,与在 Windows 8.1 / .NET 4.5.1 机器上查找完全相同的元素相比,我们查找元素集合的平均时间大约长 3 到 5 倍. 我的测试是针对 WPF DataGrid 进行虚拟化(使用回收)并获取 DataGrid 每一行内的所有单元格。
在我们的 Win10 机器上,每次 FindAll 调用获取每行中的单元格大约需要 30 - 50 毫秒甚至更长的时间。在 Win8.1 机器上,大约需要 5 - 10 毫秒。我不知道为什么,但我不认为这个问题仅限于 DataGrid,因为我们的 FindAll() 调用没有什么特别之处。
//get grid
AutomationElement gridElement = AutomationElement.RootElement.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.AutomationIdProperty, "dataGridAutomationId"));
//get all visible rows
AutomationElementCollection dataItems = gridElement.FindAll(TreeScope.Descendants,
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.DataItem));
foreach (AutomationElement dataItem in dataItems)
{
if (!string.IsNullOrEmpty(dataItem.Current.Name))
{
//call under test
AutomationElementCollection cells = dataItem.FindAll(TreeScope.Children,
new PropertyCondition(AutomationElement.ClassNameProperty, "DataGridCell"));
}
}
Run Code Online (Sandbox Code Playgroud)
AutomationElement.RootElement 的使用仅用于测试。'dataItem.FindAll()' 调用是我正在测试的。
Win 8.1 和 Win10 机器规格:
我们已经尝试通过 com wrapping 使用非托管的 MS uia API,但在 Win10 上没有看到明显的性能改进。
任何建议将不胜感激。
这似乎已在最新一轮的 Windows 10 更新 ( kb/3093266 ) 中得到修复。据我采访的一位微软支持代表说:
“UIA 频繁调用 NtQuerySystemInformation,频繁调用该 API 的性能并不令人满意。他们对特定代码路径进行了更改,不再调用该 API,这提高了整体性能。”
不幸的是,这就是他们掌握的所有信息,因此我无法确定该呼叫到底是什么导致了问题。
更新和测试后,两台机器的性能相同。
| 归档时间: |
|
| 查看次数: |
5825 次 |
| 最近记录: |