Gu.Wpf.UiAutomation icon indicating copy to clipboard operation
Gu.Wpf.UiAutomation copied to clipboard

API for default wait time when getting MainWindow

Open JohanLarsson opened this issue 6 years ago • 7 comments

Now it is

public Window MainWindow => this.GetMainWindow(TimeSpan.FromSeconds(10));

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.

JohanLarsson avatar Feb 28 '18 10:02 JohanLarsson

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");
        }
       
    }

davishoang96 avatar Apr 26 '18 14:04 davishoang96

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

JohanLarsson avatar Apr 26 '18 14:04 JohanLarsson

I did try App.WaitForMainWindow(TimeSpan.FromSeconds(1)); Although the time is still longer than 1 secs

davishoang96 avatar Apr 26 '18 14:04 davishoang96

Did it timeout when you did App.WaitForMainWindow(TimeSpan.FromSeconds(1));?

JohanLarsson avatar Apr 26 '18 17:04 JohanLarsson

Yes it did throw timeout exception

davishoang96 avatar Apr 29 '18 11:04 davishoang96

Do you have API ideas for this? Static property App.WaitForMainWindowTime is not awesome but perhaps not so bad.

JohanLarsson avatar Apr 29 '18 15:04 JohanLarsson

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.

davishoang96 avatar May 07 '18 06:05 davishoang96