Visual Basic SHDocVw.InternetExplorer IsBusy is always true, object not updating
Posted on 2014-09-02
I have a SHDocVw.InternetExplorer object that after Navigate is called does not finish loading. This browser control IsBusy = true, and ReadyState=1 despite the page in Internet Explorer can be visually seen as having finished loading. I've tried calling oIE.Refresh, but Visual Basic throws an exception (HRESULT E_FAIL has been returned from a call to a COM component). How can I get the object to show the updated webpage?
I have a project that invokes a dynamic internet explorer object (the project does not allow having an in-application WebBrowser control). This is called by Dim oIE As SHDocVw.InternetExplorer.
There are 2 calls to oIE.Navigate. The first one works perfectly. On calling the second page the page does not load as previously described. Checking the oIE object in Debug mode shows that after calling the second Navigate, the oIE.URL is still set to the first pages URL, not the second.
If the following code is added (below) (after 2nd navigate) an infinite loop results.
Do While oIE.busy Or oIE.ReadyState <> 4
Here is the interesting part. If in debug mode, an execution breakpoint is placed immediately before the 2nd navigate command, run the program, and natually execution pauses. If the program is resumed doing with no other changes, the 2nd navigate works correctly.
Naturally that suggests giving the program a timeout. However using timers to pause execution, as well as using Sleep(), but neither works. Tried multiple calls to DoEvents (with more timeouts) before 2nd Navigate but that doesn't work either.
Is there a solution to making the second Navigate load the page correctly?