0

how can I set a timeout using the webBrowser.

I know this has been asked many times and for what I see any version of visual studio has the same problem: a webbrowser with no timeout. What happens when a site blocks the whole process?

it's a problem! I've tried datediff, timer... but impossible!

Private dt As DateTime
Private dt2 As DateTime

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    WebBrowser1.Navigate("http://www.gabriels.be/")

    dt = Now
    While Not WebBrowser1.ReadyState = WebBrowserReadyState.Complete
        dt2 = Now

        Text = DateDiff(DateInterval.Second, dt2, dt)
        If DateDiff(DateInterval.Second, dt2, dt) = 6 Then
            Exit While
        End If
        Application.DoEvents()
    End While

    MsgBox("salut")
End Sub

Thank you

UPDATE:

Private Sub ButtonTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTest.Click

    Dim url As String = ""
    url = "http://www.gabriels.be/contact"
    NavigateTo(New Uri(url))

    MsgBox("stop")

    url = "http://www.google.es/"
    NavigateTo(New Uri(url))

    MsgBox("end")
End Sub

Public Sub NavigateTo(ByVal url As Uri)

    Timer1_html3.Enabled = True
    WebBrowser1.Navigate(url)

    While Not WebBrowser1.ReadyState = WebBrowserReadyState.Complete

        Application.DoEvents()
    End While
End Sub

Private Sub Timer1_html3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1_html3.Tick

    Timer1_html3.Enabled = False
    MessageBox.Show("Timeout on navigation")
End Sub

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

    If e.Url = WebBrowser1.Url And Timer1_html3.Enabled Then

        Timer1_html3.Enabled = False
    End If
End Sub

It's blocked. the webpage shows itself but I don't see the stop message of the tick event. why is that ?

eric5037
  • 23
  • 9
  • See this answer: https://stackoverflow.com/questions/4119161/how-to-set-timeout-for-webbrowser-navigate-event. It's in C#, but should be very easy to rewrite in Visual Basic. – Dávid Molnár Oct 29 '17 at 13:10
  • Thanks, David but ir doesn't work for me. I tried the same code yesterday! – eric5037 Oct 29 '17 at 19:17
  • Why doesn't it work? Could you please post the code you tried? – Dávid Molnár Oct 29 '17 at 19:21
  • I've surely deleted it but I'll go into it right now! could you try with that url: http://www.gabriels.be/ ? – eric5037 Oct 29 '17 at 20:01
  • Can you clarify specifically what you are asking for? When you say timeout do you want to happen if a website does not load in a certain amount of time? – Alexander Ryan Baggett Nov 01 '17 at 15:05
  • Yes, Alexander, absolutely. this site: http://www.gabriels.be/ does not load at all, I can't gather its html code and it blocks entirely the software I'm trying to make. I've tried to use a timer but it doesn't work. – eric5037 Nov 02 '17 at 15:16

0 Answers0