VB.Net Tutorial/Thread/Thread Creation

Материал из VB Эксперт
Версия от 15:56, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Shows multiple threads that print message

<source lang="vbnet">Imports System.Threading Module Tester

  Sub Main()
     Dim thread1 As New Thread(AddressOf Print)
     Dim thread2 As New Thread(AddressOf Print)
     Dim thread3 As New Thread(AddressOf Print)
     thread1.Name = "thread1"
     thread2.Name = "thread2"
     thread3.Name = "thread3"
     Console.WriteLine("Starting threads")
     thread1.Start()
     thread2.Start()
     thread3.Start()
  End Sub 
  Public Sub Print()
     Dim current As Thread = Thread.CurrentThread
     Console.WriteLine(current.Name & " done sleeping")
  End Sub 

End Module</source>

Starting threads
thread1 done sleeping
thread3 done sleeping
thread2 done sleeping