1

I have an application that launches a process using Process.Start. The process will either show up the actual window after a few seconds (depending on how much time it took to load), or will show a MessageBox with an error message.

After I'm using Process.Start, I want my application to wait until either the window showed up or the MessageBox showed up. I tried using WaitForInputIdle and checking if Handle is 0, but they both don't work.

How can I wait until the process emits an actual window?

Gilbert Williams
  • 175
  • 1
  • 10
  • "How can I wait until the process emits an actual window?" -- I would wait for the MainWindowHandle to be non-zero. "I tried using WaitForInputIdle and checking if Handle is 0, but they both don't work." -- *How* didn't it work? "It don't work" is not helpful for us. – Quantic Apr 21 '17 at 17:27
  • @ScottChamberlain Yes, it's written in the post. Please read it again. – Gilbert Williams Apr 21 '17 at 17:29
  • @Quantic I tried using a while loop to wait until the handle is not 0, but as soon as the process launches (even if it didn't show the window yet), the handle is not 0. Therefore it's not useful for me to use it. – Gilbert Williams Apr 21 '17 at 17:30
  • I have not found a better way other than to try and navigate to a control you know will exist after the application is open. Whatever it is you want to do after the window is open is what I would try to do right away, an exception means that control doesn't exist yet, no exception means the application opened properly and is showing the control. I am also curious if there is a better way, I don't think there is as there's nothing you can detect that is consistent across every single GUI app other than MainWindowHandle, and that existing doesn't tell you if anything else is ready or not. – Quantic Apr 21 '17 at 17:39

1 Answers1

0

I think you should just catch window openings with Automation as recommended here:

Most Efficient Way for getting notified on window open

Community
  • 1
  • 1
NetMage
  • 26,163
  • 3
  • 34
  • 55