當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET ThreadStart代理代碼示例

本文整理匯總了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
開發者ID:VB.NET開發者,項目名稱:System.Threading,代碼行數:45,代碼來源:ThreadStart

示例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
開發者ID:VB程序員,項目名稱:System.Threading,代碼行數:26,代碼來源:ThreadStart


注:本文中的System.Threading.ThreadStart代理示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。