See the question and my original answer on StackOverflow

TreeScope other than immediate children should be avoided in general. Not only it can kill performance, but it may simply never end (depending on what lies beneath...).

I suggest you refine your search using other discriminants (ControlType, Name, etc.), or use it only if you're 100% sure the subtree is really small or bounded.

BTW, that's often the reason why most automatic recorder tools fall short with UI automation, they're not clever enough to determine good AutomationProperty criteria that only humans can see, in the context of what they want to automate.