情况:
使用 VB.NET Framework 3.5 和 Visual Studio 2005 我创建了一个项目,该项目在工作中使用 WebBrowser 对象。将其分解为最基本的内容,它看起来像:
Dim bWbCompletedDocument As Boolean = False
Sub WbCompletedDocument(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
bWbCompletedDocument = True
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)Handles Me.Load
Dim th As New System.Threading.Thread(AddressOf worker)
th.SetApartmentState(Threading.ApartmentState.STA)
th.Start()
End Sub
Sub worker()
Dim Wb As New WebBrowser
Wb.ScriptErrorsSuppressed = True
AddHandler Wb.DocumentCompleted, AddressOf WbCompletedDocument
Wb.Navigate("google.de")
Dim start As Date = Now
Do While start.AddSeconds(20) > Now
Application.DoEvents()
If (bWbCompletedDocument = True) And (Wb.IsBusy = False) And (Wb.ReadyState = WebBrowserReadyState.Complete) Then
Exit Do
End If
Loop
If bWbCompletedDocument = False Then
Exit Sub
End If
'more code here
End Sub
浏览器没有 GUI,但一切正常。我导航到捕获DocumentCompleted事件的页面,检查ReadyState以及他是否IsBuisy并继续我的代码。
问题当 onLoad
事件发生
时,有些网站开始执行 JavaScript 代码。如果我在 Wb 对象加载页面后继续执行我的 .Net 代码,则 Wb 将停止执行 JavaScript。
问题
有没有办法确定当前是否有 JavaScript 在 WebBrowser-Object 中运行和/或等待它完成?