none
Looking for webbrowser timeout if page wont load RRS feed

  • Question

  • In my VB 2010 app start-up I load several tabs with a webbrowser on them, and load some pages.  It has known to get tuck on pages, wont load them and the app never finishes cranking up.

    Am looking for a time-out feature or method to abort the load.

    Thanks!

    Friday, January 17, 2014 2:59 AM

Answers

  • Well...tried Carl Cai's solution, and WebBrowser1.Stop() method didnt stop the progress of the page loading.  Just kept going.

    Hi,

    1. Stop() method worked just like clicking the stop button in Internet Explorer when loading page.

    It just cancels any pending navigation and stops any dynamic page elements, such as background sounds and animations.

    2. Maybe you could set breakpoints in WebBrowser.ProgressChanged to check whether it invoked, since it occurs when the WebBrowser control has updated information on the download progress of a document it is navigating to.

    Reference:

    WebBrowser.ProgressChanged Event (System.Windows.Forms)

    If it cost a lot time getting response form web server, that event will not invoke unless it begain to download data of the page from the web server.

    3. >>The workaround from this is however to verify the webbrowser.IsBusy, it means that the webbrowser is still busy.

    This you can use in a timer to see if it takes to long.<<

    If that event will not invoke or it invoke too late, as Cor said we should focus on how to verify whether the webbrowser takes too long, so it will not work as "expected".

    So if possible, you could share the detailed information with us:

    1). If possible, you could share your current code and the urls with us.

    2).If you load them in IE, how long will it cost in getting responses form these pages.

    In addition, I tested it with the following code:

    Public Class Form1
        Dim dct As Dictionary(Of WebBrowser, DateTime) = New Dictionary(Of WebBrowser, Date)()
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            For Each tbPage As TabPage In TabControl1.TabPages
                For Each objControl As Control In tbPage.Controls
                    If TypeOf objControl Is WebBrowser Then
                        If Not dct.ContainsKey(objControl) Then
                            dct.Add(objControl, New DateTime)
                        End If
                    End If
                Next
            Next
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            For Each tbPage As TabPage In TabControl1.TabPages
                For Each objControl As Control In tbPage.Controls
                    If TypeOf objControl Is WebBrowser Then
                        CType(objControl, WebBrowser).Navigate(" http://social.msdn.microsoft.com/Forums/en-US/home?sort=relevancedesc&brandIgnore=True&searchTerm=1")
                    End If
                Next
            Next
        End Sub
    
        Private Sub WebBrowser1_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged, WebBrowser2.ProgressChanged, WebBrowser3.ProgressChanged, WebBrowser4.ProgressChanged, WebBrowser5.ProgressChanged
            Dim wbBrowser As WebBrowser = CType(sender, WebBrowser)
            Me.Text = wbBrowser.Name
            If (Now.Minute > dct(wbBrowser).Minute Or (Now.Millisecond - dct(wbBrowser).Millisecond) > 10) Then
                wbBrowser.Stop()
            End If
        End Sub
    
        Private Sub WebBrowser1_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating, WebBrowser2.Navigating, WebBrowser3.Navigating, WebBrowser4.Navigating, WebBrowser5.Navigating
            Dim wbBrowser As WebBrowser = CType(sender, WebBrowser)
            dct(wbBrowser) = Now
        End Sub
    End Class

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, January 24, 2014 5:21 AM
    Moderator
  • Simply start a timer at the begin of the navigate and test in that if the loading still isBusy.

    It is your choice what you take as long.

    Seems to me not that difficult if you are able to use a webbrowser control.

    And don't forget to stop it if isbusy is false at document loaded.


    Success
    Cor


    Friday, January 24, 2014 8:10 AM

All replies

  • Hi,

    Welcome to MSDN.

    If you want to add a time out feature, I suggest you have a try this way shared by Riquel_Dong in this thread:

    Create a time-out for webbrowser loading method.

    Public Class Form1  
        Dim dt As DateTime  
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
            WebBrowser1.Navigate("www.yahoo.com")  
        End Sub  
        Private Sub WebBrowser1_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged  
            If (Now.Minute > dt.Minute Or (Now.Millisecond - dt.Millisecond) > 10) Then  
                WebBrowser1.Stop()  
            End If  
        End Sub  
        Private Sub WebBrowser1_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating  
            dt = Now  
        End Sub  
    End Class  
    

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 20, 2014 1:41 AM
    Moderator
  • The webbrowser does not implement all posibilities from its the AxWebbrowser from which the webbrowser is just a wrapper.

    The one who made the wrapper does probably not know that a webpage can exist from more then one document

    The workaround from this is however to verify the webbrowser.IsBusy, it means that the webbrowser is still busy.

    This you can use in a timer to see if it takes to long.

    http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.isbusy(v=vs.110).aspx


    Success
    Cor

    Monday, January 20, 2014 8:26 AM
  • Well...tried Carl Cai's solution, and WebBrowser1.Stop() method didnt stop the progress of the page loading.  Just kept going.
    Thursday, January 23, 2014 7:07 PM
  • Hi Cor,

    Could you share more details on how to implement what you hint at?

    Steve

    Thursday, January 23, 2014 7:09 PM
  • Well...tried Carl Cai's solution, and WebBrowser1.Stop() method didnt stop the progress of the page loading.  Just kept going.

    Hi,

    1. Stop() method worked just like clicking the stop button in Internet Explorer when loading page.

    It just cancels any pending navigation and stops any dynamic page elements, such as background sounds and animations.

    2. Maybe you could set breakpoints in WebBrowser.ProgressChanged to check whether it invoked, since it occurs when the WebBrowser control has updated information on the download progress of a document it is navigating to.

    Reference:

    WebBrowser.ProgressChanged Event (System.Windows.Forms)

    If it cost a lot time getting response form web server, that event will not invoke unless it begain to download data of the page from the web server.

    3. >>The workaround from this is however to verify the webbrowser.IsBusy, it means that the webbrowser is still busy.

    This you can use in a timer to see if it takes to long.<<

    If that event will not invoke or it invoke too late, as Cor said we should focus on how to verify whether the webbrowser takes too long, so it will not work as "expected".

    So if possible, you could share the detailed information with us:

    1). If possible, you could share your current code and the urls with us.

    2).If you load them in IE, how long will it cost in getting responses form these pages.

    In addition, I tested it with the following code:

    Public Class Form1
        Dim dct As Dictionary(Of WebBrowser, DateTime) = New Dictionary(Of WebBrowser, Date)()
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            For Each tbPage As TabPage In TabControl1.TabPages
                For Each objControl As Control In tbPage.Controls
                    If TypeOf objControl Is WebBrowser Then
                        If Not dct.ContainsKey(objControl) Then
                            dct.Add(objControl, New DateTime)
                        End If
                    End If
                Next
            Next
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            For Each tbPage As TabPage In TabControl1.TabPages
                For Each objControl As Control In tbPage.Controls
                    If TypeOf objControl Is WebBrowser Then
                        CType(objControl, WebBrowser).Navigate(" http://social.msdn.microsoft.com/Forums/en-US/home?sort=relevancedesc&brandIgnore=True&searchTerm=1")
                    End If
                Next
            Next
        End Sub
    
        Private Sub WebBrowser1_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged, WebBrowser2.ProgressChanged, WebBrowser3.ProgressChanged, WebBrowser4.ProgressChanged, WebBrowser5.ProgressChanged
            Dim wbBrowser As WebBrowser = CType(sender, WebBrowser)
            Me.Text = wbBrowser.Name
            If (Now.Minute > dct(wbBrowser).Minute Or (Now.Millisecond - dct(wbBrowser).Millisecond) > 10) Then
                wbBrowser.Stop()
            End If
        End Sub
    
        Private Sub WebBrowser1_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating, WebBrowser2.Navigating, WebBrowser3.Navigating, WebBrowser4.Navigating, WebBrowser5.Navigating
            Dim wbBrowser As WebBrowser = CType(sender, WebBrowser)
            dct(wbBrowser) = Now
        End Sub
    End Class

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, January 24, 2014 5:21 AM
    Moderator
  • Simply start a timer at the begin of the navigate and test in that if the loading still isBusy.

    It is your choice what you take as long.

    Seems to me not that difficult if you are able to use a webbrowser control.

    And don't forget to stop it if isbusy is false at document loaded.


    Success
    Cor


    Friday, January 24, 2014 8:10 AM