我要限制等待的网页浏览器加载; 我开始与下面的code正在等待的网页浏览器开始下一个动作之前加载; 我想等待被限定于60秒时,如果该网页不加载则code将执行下一个动作; 任何帮助是AP preciated:
I want to Limit Waiting for Webbrowser to Load; I started with the code below that is waiting for Webbrowser to load before starting next action; I want the waiting to be limited to 60 seconds, if the webpage does not load then the code will perform the next action; Any help is appreciated:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
WebBrowser1.Navigate("www.mekdam.com")
While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While
End Sub
End Class
感谢
您应该检查你的的readyState
在 DocumentCompleted
事件。这样,就不会挂起你的应用程序。
You should check your ReadyState
in the DocumentCompleted
event. That way it won't hang your application.
如果您添加一个计时器可以取消页面的加载,如果时间太长:
If you add a timer you can cancel the loading of the page if it takes too long:
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
WebBrowser1.Navigate("http://www.msn.co.uk")
Timer1.Interval = 2000
Timer1.Enabled = True
End Sub
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
'If the timer is not running then we are not waiting for the document to complete
If Not Timer1.Enabled Then Exit Sub
'Check the document that just loaded is the main document page (not a frame) and that the control is in the ready state
If e.Url.AbsolutePath = CType(sender, WebBrowser).Url.AbsolutePath AndAlso WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
'we loaded the page before the timer elapsed
Timer1.Enabled = False
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'timer has elapsed so cancel page load
WebBrowser1.Stop()
'Disable the timer
Timer1.Enabled = False
End Sub
上一篇:从GONE的可见设置能见度可见后没有得到的RelativeLayout的的getHeight()能见度、GONE、getHeight、RelativeLayout
下一篇:大会的Microsoft.Office.Interop.Word,版本= 15.0.0.0使用Microsoft.Vbe.Interop,版本= 15.0.0.0版本、大会、Office、Word