2014-01-09 67 views
0

我想在窗體中的web瀏覽器組件中加載一個網頁。頁面加載後連接的Wlan

在我加載頁面之前,我運行一個批處理文件連接到選定的Wlan連接。

問題是Wlan在經過一定的延遲後正在連接,此時網絡瀏覽器會加載未加載的網頁。

如何在添加這兩個事件

pe.WaitForExit() 

webBrowser1.Navigate("http://10.10.116.5:8090/httpclient.html") 

下面之間的延遲是DocumentCompleted事件

Sub WebBrowser1DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) 
     Do While webBrowser1.ReadyState <> WebBrowserReadyState.Complete 

      MsgBox("Here3") 
      webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("username").Item(0).SetAttribute("value",username) 
      webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("password").Item(0).SetAttribute("value",password) 

      webBrowser1.Document.GetElementById("logincaption").Focus() 
      webBrowser1.Document.GetElementById("logincaption").InvokeMember("click") 
      MsgBox("logged in") 
     Loop 
    End Sub 

有人可以幫助我

回答

1

你可以嘗試檢查「狀態「的BackgroundWorker中的批處理文件,並在工作人員完成後加載頁面。

Public Sub Start() 
    Dim file As String = "path_and_name_of_file" 
    'TODO: Execute batch "path_and_name_of_file". 
    Me.BackgroundWorker1.RunWorkerAsync(file) 
End Sub 

Private Sub BackgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork 

    Dim path As String = CStr(e.Argument) 
    Dim watch As New Stopwatch() 
    Dim timedOut As Boolean = False 

    watch.Start() 

    Do 

     Try 
      Using stream As IO.Stream = New IO.FileStream(path, IO.FileMode.Open) 
      End Using 
      Exit Do 
     Catch ex As Exception 
     End Try 

     'Time out after 2 minutes. 
     If (watch.Elapsed.TotalMinutes > 2) Then 
      timedOut = True 
      Exit Do 
     Else 
      Threading.Thread.Sleep(500) '<- Give thread some rest. 
     End If 

    Loop 

    watch.Stop() 

    ''Uncomment this line if you will add a 3 second delay AFTER executed batch: 
    'If (Not cancelled) Then 
    ' Threading.Thread.Sleep(3000) 
    'End If 

End Sub 

Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted 
    'TODO: Load page. 
End Sub 

編輯

試想想起來了,你可以嘗試ping IP地址:

Private Sub BackgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork 

    Dim watch As New Stopwatch() 
    Dim timedOut As Boolean = False 

    watch.Start() 

    Do 

     Try 
      If (My.Computer.Network.Ping("10.10.116.5", 100)) Then 
       Exit Do 
      End If 
     Catch ex As Exception 
     End Try 

     'Time out after 2 minutes. 
     If (watch.Elapsed.TotalMinutes > 2) Then 
      timedOut = True 
      Exit Do 
     Else 
      Threading.Thread.Sleep(500) '<- Give thread some rest. 
     End If 

    Loop 

    watch.Stop() 

End Sub