如何使用webBrowser设置超时。
我知道这已被多次询问,而且我看到任何版本的visual studio都有同样的问题:没有超时的webbrowser。当网站阻止整个过程时会发生什么?
这是一个问题!我已尝试过约会,计时器......但不可能!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
谢谢
更新:
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
被封锁了。网页显示自己,但我没有看到tick事件的停止消息。这是为什么 ?