Open JohanLarsson opened 6 years ago
I have this GetMainWindow function for the program. I did try TimeSpan.FromSeconds(5) but i'm still getting infinity waiting for the respond. Do you have any idea?
public static void GetMainWindow()
{
try
{
Process AttachProcess = WindowInteraction.GetProcess(ProcessForm.targetproc);
App = Application.Attach(AttachProcess.Id);
MainWindow = App.GetMainWindow(TimeSpan.FromSeconds(5));
}
catch
{
throw new Exception("Cannot get MainWindow");
}
}
Sounds like a bug, have you seen anything dumb in the code? https://github.com/GuOrg/Gu.Wpf.UiAutomation/blob/2916d6685b3cd993fd1bebd69b64ef7568551119/Gu.Wpf.UiAutomation/Application.cs#L344-L369
I did try
App.WaitForMainWindow(TimeSpan.FromSeconds(1));
Although the time is still longer than 1 secs
Did it timeout when you did App.WaitForMainWindow(TimeSpan.FromSeconds(1));
?
Yes it did throw timeout exception
Do you have API ideas for this? Static property App.WaitForMainWindowTime
is not awesome but perhaps not so bad.
Yeah I fixed the issue by putting: Application.WaitForMainWindow(AttachProcess, TimeSpan.FromSeconds(1));
before the App = Application.Attach(AttachProcess.Id);
It worked perfectly fine. Thanks Johan.
Now it is
Which is not very nice and the time is probably too short for real applications. Static property is an alternative but not very nice. Another alternative is attribute.