tags:

views:

21

answers:

0

I have a WinForms app that starts a wpf process running using Process.Start. I would like to know when the WPF process is finished loading and I can access the process.MainWindowHandle property (its 0 before its completly loaded).

I tried polling but the handle is always 0. However, if I debug and wait (after Process.Start) for the WPF app to load - I then will get the correct handle.

Does not work:

int maxCount=100000;
int count=0;
do
{
    wpfProcess.WaitForInputIdle();
    _hWnd = net4ReconProcess.MainWindowHandle;
    count++;
} while (_hWnd.ToInt32() == 0 || count > maxCount);