VB.NET 多线程简化步骤
上篇的链接,http://www.2cto.com/kf/201111/110904.html
其实都在百度知道里
http://zhidao.baidu.com/question/281582074.html?fr=qrl&cid=867&index=4&fr2=query
过程只需要1个,线程你要多少就需要创建多少,这个可以用循环来创建:
Dim Thd(99) As Thread
For i As Integer =0 to 99
Thd(i)=New Thread(AddressOf Start)
Thd(i).Start()
Next
如果你不需要保留这些线程的引用
那个数组也可以省略掉
直接在循环中(New Thread(AddressOf Start)).Start()就行了
下面给出我理解的代码
Imports System.Threading
Public Class Form1
Private Sub Start() '线程1
Dim I As Integer
For I = 1 To 100000000 Step +1
Label1.Text = I
Label2.Text = I
Label3.Text = I
Label4.Text = I
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Control.CheckForIllegalCrossThreadCalls = False
Dim Thd(99) As Thread
For i As Integer = 0 To 4
Thd(i) = New Thread(AddressOf Start)
Thd(i).Start()
Next
End Sub
End Class
摘自Shine的圣天堂-〃敏〃