Link to home
Start Free TrialLog in
Avatar of kevandju
kevandjuFlag for United States of America

asked on

Refreshing AxWebBrowser in background while other browser is displayed

I have a simple program that navigates 4 browser windows to 4 different web sites and then after my timer elapses at 20 seconds the browser 1 will hide then 2 will show all the way through the 4 windows looping.  Problem is that I am sending a refresh command to the browser while it is in the background and the browser window does not refresh until it is visible again.  I have tried both AxWebBrowser.Refresh() and AxWebBrowser.Refresh2().  Refresh doesn't seem to work at all and Refresh2 will work but only when the browser is visible.  Here is code below.


 Private Sub Timer1_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
        On Error Resume Next

        Static intBrowserID As Integer = 0

        Select Case intBrowserID
            Case 0
                AxWebBrowser1.Visible = True
                AxWebBrowser2.Visible = False
                'AxWebBrowser2.Refresh2()
                AxWebBrowser3.Visible = False
                AxWebBrowser4.Visible = False
                AxWebBrowser4.Refresh2()
            Case 1
                AxWebBrowser1.Visible = False
                AxWebBrowser1.Refresh2()
                AxWebBrowser2.Visible = True
                AxWebBrowser3.Visible = False
                AxWebBrowser4.Visible = False
            Case 2
                AxWebBrowser1.Visible = False
                AxWebBrowser2.Visible = False
                AxWebBrowser2.Refresh2()
                AxWebBrowser3.Visible = True
                AxWebBrowser4.Visible = False
            Case 3
                AxWebBrowser1.Visible = False
                AxWebBrowser2.Visible = False
                AxWebBrowser3.Visible = False
                AxWebBrowser3.Refresh2()
                AxWebBrowser4.Visible = True
        End Select
        intBrowserID += 1
        If intBrowserID > 3 Then
            intBrowserID = 0
        End If

    End Sub
Avatar of S-Twilley
S-Twilley

If refresh isn't working, what about navigating to it's own URL... soemthing like

AxWebBrowser.Navigate2(AxWebBrowser.LocationURL)

==========

if it doesn't register since it's the same URL, navigate away, and then back again

Dim locURL as string = AxWebBrowser.LocationURL
AxWebBrowser.Navigate2("")
AxWebBrowser.Navigate2(locUR)


sorry, it should have read:

Dim locURL as string = AxWebBrowser.LocationURL
AxWebBrowser.Navigate2("")
AxWebBrowser.Navigate2(locURL)
Avatar of kevandju

ASKER

I'm trying it right now.  What exactly is the difference between .Navigate and .Navigate2?  I don't get what the 2 means.
It may be related to this bug:

BUG: DocumentComplete Does Not Fire When WebBrowser Is Not Visible
http://support.microsoft.com/default.aspx?scid=kb;en-us;259935

Microsoft recommends not using an invisible WebBrowser, but instead position the WebBrowser control off-screen so it is not in view.
I believe navigate2 was an updated version of Navigate... but the old one was left in there for compatibility
ASKER CERTIFIED SOLUTION
Avatar of angelfeijoo
angelfeijoo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That works perfectly angelfeijoo.  I already had the 4 browser windows overlayed.  I just didn't know about the bringtofront command.  Thanks for the insight!!
You're welcome!