How to wait for window to load (threading)?

B

Brett

Say I open an IE window and call the Navigate() method. A web page opens.
I use a delegate to capture the DocumentComplete and NavigateComplete2
events. However, they fire slightly before the page completely loads. This
article addresses the above issues for OnBeforeNavigate2 event:
http://www.codeproject.com/buglist/iefix.asp?df=100&forumid=13326&exp=0&select=408890. I
changed it to work with DocumentComplete(), which seems to work well for the
ActiveX object.

Problem is that I need access to an actual IE window, not the ActiveX object
on a form. So when I marshall the InternetExplorer object:

ie = new SHDocVw.InternetExplorerClass();
ie = (SHDocVw.InternetExplorerClass)
System.Runtime.InteropServices.Marshal.CreateWrapperOfType(
axWebBrowser1.GetOcx(),
typeof(SHDocVw.InternetExplorerClass)
);

I end up with the page opening in the form, where the ActiveX object opened
it. This causes rendering problems such as JS script errors and such.

My question is how can I wait for the webpage to completely load? I'm open
to suggestions.

Thanks,
Brett
 
S

Saish

hi
use the following code after using navigate and before using delegate

while(ie.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE )




hope this will help u
with regards
saish
 
B

Brett

This goes into an infinite loop. The current thread never gives control
back to IE because it is always looping on the condition. I've also tried
it with Application.DoEvents(), which doesn't help.

while(IE_Inst.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE ){
Debug.WriteLine("In while loop, IE_Inst.ReadyState = " +
IE_Inst.ReadyState);
Application.DoEvents();}

Brett


hi
use the following code after using navigate and before using delegate

while(ie.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE )



hope this will help u
with regards
saish
 
B

Brett

This seems to be doing the trick. I'm putting it in the same place you
mentioned previously.

private delegate void DelegateWasteSomeTime();
.....

//placed in DocumentComplete event before next navigation. Allows current
page to fully load.
DelegateWasteSomeTime wstdel = new
DelegateWasteSomeTime(this.WasteSomeTime);
wstdel.BeginInvoke(null, null);

private void WasteSomeTime()
{
System.Threading.Thread.Sleep(2000);
}

Brett
 
B

Brett

Scratch that. It's flying right through that line. Even if I do spin off a
new thread, I'd tie the current thread up by waiting for the new thread to
complete some type of loop. I'd be in the same situation.

Brett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top