分类:
2008-10-13 16:09:05
Imports System Imports System.Threading Class MyApp Shared Sub Main() '*** long-hand syntax for creating a thread Dim MyHandler As New ThreadStart(AddressOf TedsCode.MyAsyncTask) Dim ThreadA As New Thread(MyHandler) ThreadA.Start(); '*** short-hand syntax for creating a thread Dim ThreadB As New Thread(AddressOf TedsCode.MyAsyncTask) ThreadB.Start() End Sub End Class
Imports System Imports System.Threading Class MyApp Shared Sub Main() Dim ThreadA As New TedsThreadClass(1, "Bob") ThreadA.Start() Dim ThreadB As New TedsThreadClass(2, "Betty") ThreadB.Start() End Sub End Class Class TedsThreadClass '*** define custom fields and constructor with parameterized data Protected x As Integer Protected y As String Sub New(ByVal X as Integer, ByVal Y As String) Me.x = X Me.y = Y End Sub '*** instance method used to run asynchronous task Sub MyASyncTask() '*** this code has access to x and y End Sub '*** encapsulated threading support Protected InnerThread As New Thread(AddressOf Me.MyAsyncTask) Public Sub Start() InnerThread.Start() End Sub End Class