How to know if the current browser is loaded with C# code
I am working with the Image generation of a browser, but doing so i am taking a开发者_Go百科 snapshot of the browser from the code, in windows form. But if the browser is not loaded in the specific time (suppose 15 seconds) then a blank snapshot occur. Anyone help me with this .
I'm not entirely sure if I understand exactly what you're trying to do, but I'll take a stab at it: It sounds like you're trying to open whatever program is set as the user's default web browser, and then do something like a BitBlt
to take a screenshot of it.
However, as you've noticed, it's difficult to just wait a pre-defined interval and hope the browser has completely loaded. Instead, you could try something like WaitForIdleInput
after running the process, which will suspend the thread's execution until the process has finished initializing and is idle (waiting for user input). This should allow the browser to finish loading before you proceed with taking the snapshot.
Something like the following code:
//start the web browser
System.Diagnostics.Process proc = System.Diagnostics.Process.Start("iexplore.exe");
//wait for it to completely finish loading
proc.WaitForInputIdle();
//take your screenshot, or whatever
//...
精彩评论