1
Answer

Wait for a process to intitialise and have a handle != IntPtr.Zero

chris sunter

chris sunter

16y
2.4k
1
All, 

I am trying to start a process and wait for the handle to recieve a value.  This will occur when the window is fully initialised.

                    ProcessStartInfo process = new ProcessStartInfo(progName);
                    process.Arguments = arguments.Trim();
                    // start process
                    Process aProc = new Process();
                    aProc = Process.Start(process);
                   
                    bool gotHandle = false;
                  
                    while (! gotHandle)
                    {
                        if (aProc.MainWindowHandle == IntPtr.Zero)
                        {
                            Console.WriteLine("Not got " + ap);
                            Thread.Sleep(1000);

                        }
                        else
                        {
                            Console.WriteLine("GOT");
                            gotHandle = true;
                        }
                    }

                    //MessageBox.Show(""+ aProc.MainWindowHandle);
                    return aProc;
                }


All I am recieveing in the Console is "Not got  0".

Any help is very welcome. 
Answers (1)