in src/Desktop/UIAutomation/TreeWalkers/TreeWalkerForLive.cs [106:160]
private void PopulateChildrenTreeNode(A11yElement rootNode, int startId)
{
int childId = startId;
IUIAutomationTreeWalker walker = A11yAutomation.GetTreeWalker(this.WalkerMode);
IUIAutomationElement child = (IUIAutomationElement)rootNode.PlatformObject;
if (child != null)
{
try
{
child = walker.GetFirstChildElement(child);
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception ex)
{
ex.ReportException();
child = null;
System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex);
}
#pragma warning restore CA1031 // Do not catch general exception types
while (child != null)
{
#pragma warning disable CA2000 // childNode will be disposed by the parent node
// Create child without populating basic property. it will be set all at once in parallel.
var childNode = new DesktopElement(child, true, false)
{
UniqueId = childId++
};
#pragma warning restore CA2000 // childNode will be disposed by the parent node
rootNode.Children.Add(childNode);
childNode.Parent = rootNode;
childNode.TreeWalkerMode = this.WalkerMode;
this.Elements.Add(childNode);
try
{
child = walker.GetNextSiblingElement(child);
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception ex)
{
ex.ReportException();
child = null;
System.Diagnostics.Trace.WriteLine("Tree walker exception: " + ex);
}
#pragma warning restore CA1031 // Do not catch general exception types
}
}
Marshal.ReleaseComObject(walker);
}