开发者

C# Making program wait until browser finish loading webpage

开发者 https://www.devze.com 2023-01-21 08:42 出处:网络
How do i make my program to wait until webpage finish loading befor开发者_Go百科e executing next statement. I tried Process::WaitForInputIdle(); but it doesn\'t wait.

How do i make my program to wait until webpage finish loading befor开发者_Go百科e executing next statement. I tried Process::WaitForInputIdle(); but it doesn't wait.

ProcessStartInfo pInfo = new ProcessStartInfo("firefox.exe");

pInfo.Arguments = "http://example.com";

Process p  = Process.Start(pInfo);

p.WaitForInputIdle();

pInfo.Arguments = "http://example.net";

p = Process.Start(pInfo);

p.WaitForInputIdle();


You can't. The problem here is that Firefox does not communicate back when the web page has loaded. You will for example see issues when Firefox wants to update itself before it opens the web page. How is it going to communicate back when the page is loaded? In between, the entire firefox.exe executable has been replaced, and the connection with your Process has been long lost.

The WaitForInputIdle does a very specific job, and this is not what you expect. Windows works through a message pump. When you e.g. move the mouse over a window, a message is send to that window. WaitForIdleInput returns when the application has processed the first message it has received, so when Windows knows it is 'responsive'.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号