本文整理匯總了VB.NET中System.Threading.ThreadStart代理的典型用法代碼示例。如果您正苦於以下問題:VB.NET ThreadStart代理的具體用法?VB.NET ThreadStart怎麽用?VB.NET ThreadStart使用的例子?那麽, 這裏精選的代理代碼示例或許可以為您提供幫助。
在下文中一共展示了ThreadStart代理的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Test
' 導入命名空間
Imports System.Threading
Public Class Test
<MTAThread> _
Shared Sub Main()
' To start a thread using a static thread procedure, use the
' class name and method name when you create the ThreadStart
' delegate. Visual Basic expands the AddressOf expression
' to the appropriate delegate creation syntax:
' New ThreadStart(AddressOf Work.DoWork)
'
Dim newThread As New Thread(AddressOf Work.DoWork)
newThread.Start()
' To start a thread using an instance method for the thread
' procedure, use the instance variable and method name when
' you create the ThreadStart delegate. Visual Basic expands
' the AddressOf expression to the appropriate delegate
' creation syntax:
' New ThreadStart(AddressOf w.DoMoreWork)
'
Dim w As New Work()
w.Data = 42
newThread = new Thread(AddressOf w.DoMoreWork)
newThread.Start()
End Sub
End Class
Public Class Work
Public Shared Sub DoWork()
Console.WriteLine("Static thread procedure.")
End Sub
Public Data As Integer
Public Sub DoMoreWork()
Console.WriteLine("Instance thread procedure. Data={0}", Data)
End Sub
End Class
' This code example produces the following output (the order
' of the lines might vary):
'
'Static thread procedure.
'Instance thread procedure. Data=42
示例2: New ThreadStart
' 導入命名空間
Imports System
Imports System.Drawing
Imports System.Threading
Imports System.Windows.Forms
Imports System.IO
public class MainClass
Shared Sub Main()
Dim Thrd As Thread
Dim TStart As New ThreadStart(AddressOf BusyThread)
Thrd = New Thread(TStart)
Thrd.Priority = ThreadPriority.Highest
Thrd.Start()
End Sub
Shared Sub BusyThread()
While True
Console.WriteLine("in thread")
End While
End Sub
End Class