.Imports System
.Imports System.Threading
.
.
.Module Module1
.
. Sub Main()
.
. Dim mythread1 As Thread
. Dim mythread2 As Thread
. Dim mythread3 As Thread
. '创建线程对象
. mythread1 = New Thread(AddressOf mythreadrun)
. mythread2 = New Thread(AddressOf mythreadrun)
. mythread3 = New Thread(AddressOf mythreadrun)
. Console.WriteLine(Now.ToLongTimeString & "线程对象创建完毕,开始执行线程")
. '执行线程
. mythread1.Start("线程1")
. mythread2.Start("线程2")
. mythread3.Start("线程3")
. '等待线程完成
. mythread1.Join()
. mythread2.Join()
. mythread3.Join()
. '线程执行完毕
. Console.WriteLine(Now.ToLongTimeString & "线程执行完毕!")
. End Sub
. Public Sub mythreadrun(ByVal data As Object)
. Console.WriteLine(data & "," & Now.ToLongTimeString & "执行")
. End Sub
.End Module
Dim mythread1 As Thread 初始化Thread 类的新实例,指定允许对象在线程启动时传递给线程的委托。
线程不会在创建时开始执行。 若要为执行而调度线程,调用start方法。
上面代码创建了3个thread对象,然后调用它们的start方法执行它们
调用join方法等它们执行完毕
可在VB.NET2010中建立一个新的Console应用程序,然后在模块中编写以上代码
New Thread(AddressOf mythreadrun) 构造函数中必须将要做为线程执行的函数做为参数传入
mythread1.Start("线程1") start方法可以在执行线程时,向其传入参数
Imports System Imports System.Threading