Mega Code Archive

 
Categories / VB.Net Tutorial / Thread
 

Shows multiple threads that print message

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 Starting threads thread1 done sleeping thread3 done sleeping thread2 done sleeping