Threading multiple WebBrowser in VB .net
I'm building a multiple webbrowser inside tabs( 1 predefine webbrowser control per tab) and I want them all to load at the same time or other words must run in thread. Unfortunately I feel a valid fact came from the error message that this is something not possible. Pls help me to check my simple program code below and its error in case i tried releasing 2 webbrowser controls but when I lea开发者_开发知识库ve it to single web browser control it works fine. Any workaround?
Imports System.Threading
Public Class Form1
Dim mythread1 As Thread
Dim mythread2 As Thread
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mythread1 = New Thread(AddressOf mysub1)
mythread2 = New Thread(AddressOf mysub2)
mythread1.IsBackground = True
mythread2.IsBackground = True
mythread1.Start()
mythread2.Start()
End Sub
Public Sub mysub1()
Dim HTML As String
WebBrowser1.Navigate("about:blank")
mythread1.Abort()
End Sub
Public Sub mysub2()
WebBrowser2.Navigate("about:blank")
mythread2.Abort()
End Sub
Following msdn article: "There are four methods on a control that are thread safe to call: Invoke, BeginInvoke, EndInvoke and CreateGraphics and InvokeRequired property"
You cannot make a direct call to WebBrowser1.Navigate from another thread
Follow How to: Make Thread-Safe Calls to Windows Forms Controls
Webbrowsers are by default asynchronous so you don't need to thread them as they will each run in order.
If it's speed your after then maybe switch up to webclient or httpwebrequest. You don't need to download the images to run and can multi-thread those.
精彩评论