New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Application.GetAllTopLevelWindows() is slow #616
Comments
Could you provide some code with what you've done? Would be easier to get a better idea about what you're trying to do |
var app = FlaUI.Core.Application.Attach("xxx.exe");
using (var automation = new UIA3Automation())
{
var window = app.GetAllTopLevelWindows(automation).FirstOrDefault(t => t.Name == "Client.Main.Views.AppendViewModel");
window.FindFirstDescendant(t => t.ByName("Accept")).AsButton()?.Invoke();
} |
Can you please measure each call individually ( var window = automation.GetDesktop().FindFirstChild(cf =>
cf.ByControlType(ControlType.Window)
.And(cf.ByProcessId(app.ProcessId))
.And(cf.ByName("Client.Main.Views.AppendViewModel"))
); |
GetAllTopLevelWindows is slower, taking 3 seconds, but the new method you provided is effective, reducing the time to 0.2 seconds. Additionally, GetAllTopLevelWindows is not as slow as before, perhaps because my system has been restarted. |
When it gets all windows from the top level (desktop), UIA queries the Windows-Objects underneath and it might encounter a window (application) that is hanging for some time until it responds, making the whole request slow. If you want, you could try to get each window from the |
How do I enumerate it? The code in the loop passes quickly, and the time is concentrated on FindAllChildren. |
In raw UIA you would
You can find more examples of usage of the TreeWalker here. This unfortunately will be slower than just asking for |
I tested the following code based on your suggestion, and it speed is basically the same as FindAllChildren().
According to the test, I found that the time is concentrated in |
@SunnyDesignor I have only ever experienced a slow down in getting a window when that window is not responding or the OnCreateAutomationPeer method is taking a long time to finish producing the automation peers for the controls. If it's not a .NET application it could be taking a longer time to respond to the WM_GETOBJECT message but I am not very familiar with how to dig into that. |
Application.GetAllTopLevelWindows is slow, it takes 5 to 10 seconds, but GetMainWindow is fast, <0.1sec. I roughly checked the source code and found that GetAllTopLevelWindows searched the entire desktop. I just want to get a window with a matching name within a specific process. I can't accept the long wait. Is this a flaw in the project, or should I use other methods?
The text was updated successfully, but these errors were encountered: