Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait for WPF app to load after starting with Process.Start()

Tags:

process

wpf

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);
like image 700
TheSean Avatar asked Oct 25 '25 16:10

TheSean


1 Answers

Add process.Refresh(); to the while loop.

like image 137
Captain Garforce Avatar answered Oct 28 '25 06:10

Captain Garforce