vb.net-如何在多线程下获取Webbrowser InnerHtml

时间:2018-12-19 06:29:51

标签: vb.net multithreading

我在浏览器中使用SetApartmentState

Private Sub frmMain_Shown(sender As Object, e As EventArgs) Handles Me.Shown
    Dim th As System.Threading.Thread = New Threading.Thread(AddressOf Task_A)
    th.SetApartmentState(ApartmentState.STA)
    th.Start()        
End Sub

Public Sub Task_A()
    Dim frmBuild = New NewForm() 
    Dim WebBrowser1 = New WebBrowser()
    Application.Run(frmBuild)
    frmBuild.Controls.Add(WebBrowser1)
    WebBrowser1.CreateControl()
End Sub

Private Delegate Function GetInnerHTMLCallBack() As String        
Private Function GetInnerHTML() As String
    If WebBrowser1.InvokeRequired Then
        Return CStr(WebBrowser1.Invoke(New GetInnerHTMLCallBack(AddressOf GetInnerHTML)))
    Else
        Return WebBrowser1.Document.Body.InnerHtml
    End If
End Function

Dim innerHTML As String = GetInnerHTML()  
frmMain.textbox1.text=innerHTML
Dim docs As mshtml.HTMLDocument = WebBrowser1.Document.DomDocument  

我什么也没得到,如何在交叉线程中得到或设置字符串? 我在多线程方面很差。

0 个答案:

没有答案