views:

237

answers:

2

I am loading a page in a webbrowser control. How can i check when its completely done? i know about DocumentCompleted, but one page may call it 5 or many more times. How do i check when its completely done?

+2  A: 

Does the ReadyState property help?
There is also a boolean property Busy. I guess, that should help too.

shahkalpesh
it look like it solved my problem. i cant reproduce the bug consistently so it may be a few days until i know
acidzombie24
+1  A: 

Your DocumentCompleted handler gets called for the main document, as well for each frame within that document. The number of calls depends on the particular webpage you've opened.

Using the ReadyState property as shahkalpesh suggested sounds reasonable, although I know another way that will work. Presuming your event handler has this signature:

  void OnDocumentComplete( object pDisp, ref object url )

and you have a reference to the main document, then you can check

  pDisp == mainDoc

to see if the call is originating from the main document. In my experience you should also cast pDisp to IWebBrowser2, then cast its Document property to IHTMLDocument2, then check that its body property is non-null. If so, then the document has been completely loaded.

HappyNomad