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.
Loading
AlanPosted Sep 25, 2008, 6:37 AM
I'd try using the Process.WaitForInputIdle() method instead:
http://msdn.microsoft.com/en-us/library/8d7363e2.aspx
By the time that method returns, the windows handle should have been allocated.