本文整理汇总了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;未经允许,请勿转载。 |
请发表评论