From: Dustin Campbell on 20 Dec 2006 12:02 > After much investigation and armed with your kind advice Dustin I have > found the problem. > > There is a delay between the launch of app.exe and the availability of > the Hwnd that i'm searching for. > > I have managed to overcome this by using the following: - > > while (handle == 0) > { > handle = FindWindow(null, "title of application"); > } > //here i make the calls to the api's only once my hwnd has a value > that isn't 0. > > The only problem with this is it causes a fairly significant delay > between the time of launching my c# code, and the app.exe actually > being launched. (Which surprised me because my P.Start() is actually > BEFORE the while code i have placed above. > > Any ideas why this delay may be happening and how i might overcome it? You could get a similar effect by calling Process.WaitForInputIdle() after calling Process.Start(). Assuming that the process that your starting has a GUI (it appears to), this will block your thread until it is ready. Process.Start() does just that -- it starts the process. After starting the process, there is initialization that takes place in that process before the main window is created. However, the Process.Start() call will have already returned by the time that happens. There's no way to actually speed up the start of that process -- you simply don't have control of that. A simple solution to keep your application from blocking might be to just use a System.Windows.Forms.Timer on your form and check for the handle ever 10 milliseconds or so. Best Regards, Dustin Campbell Developer Express Inc.
From: garyusenet on 20 Dec 2006 12:21
Dustin. Process.WaitForInputIdle(); Is doing exactly what I needed. It's achieving the same effect as my while loop, but it isn't creating the significant (approx 10 second) delay. Thank you, Your advice has been invaluable. Gary- Dustin Campbell wrote: > > After much investigation and armed with your kind advice Dustin I have > > found the problem. > > > > There is a delay between the launch of app.exe and the availability of > > the Hwnd that i'm searching for. > > > > I have managed to overcome this by using the following: - > > > > while (handle == 0) > > { > > handle = FindWindow(null, "title of application"); > > } > > //here i make the calls to the api's only once my hwnd has a value > > that isn't 0. > > > > The only problem with this is it causes a fairly significant delay > > between the time of launching my c# code, and the app.exe actually > > being launched. (Which surprised me because my P.Start() is actually > > BEFORE the while code i have placed above. > > > > Any ideas why this delay may be happening and how i might overcome it? > > You could get a similar effect by calling Process.WaitForInputIdle() after > calling Process.Start(). Assuming that the process that your starting has > a GUI (it appears to), this will block your thread until it is ready. > > Process.Start() does just that -- it starts the process. After starting the > process, there is initialization that takes place in that process before > the main window is created. However, the Process.Start() call will have already > returned by the time that happens. There's no way to actually speed up the > start of that process -- you simply don't have control of that. > > A simple solution to keep your application from blocking might be to just > use a System.Windows.Forms.Timer on your form and check for the handle ever > 10 milliseconds or so. > > Best Regards, > Dustin Campbell > Developer Express Inc. |