VB.Net/Thread/Thread Join
Join a Thread
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()
Console.WriteLine(Thrd.ThreadState.ToString("G"))
Console.WriteLine("Thrd.IsAlive " & Thrd.IsAlive)
If Thrd.IsAlive Then
Thrd.Abort()
Thrd.Join()
End If
End Sub
Shared Sub BusyThread()
While True
"Console.Write("thread ")
End While
End Sub
End Class
Simple Thread Join
Imports System.Threading
Public Class MainClass
Shared Dim A As Thread = New Thread(AddressOf MethodA)
Shared Dim B As Thread = New Thread(AddressOf MethodB)
Shared Dim C As Thread = New Thread(AddressOf MethodC)
Public Shared Sub Main()
A.Name = "A"
A.Start()
B.Name = "B"
B.Start()
C.Name = "C"
C.Start()
End Sub
Shared Sub MethodA()
Dim I As Integer
B.Join()
C.Join()
For I = 0 To 250
System.Console.Write("A")
Next
End Sub
Shared Sub MethodB()
Dim I As Integer
For I = 0 To 250
System.Console.Write("B")
Next
End Sub
Shared Sub MethodC()
Dim I As Integer
For I = 0 To 250
System.Console.Write("C")
Next
End Sub
End Class
Thread A Join Thread B
Imports System.Threading
Public Class MainClass
Shared Dim A As Thread = New Thread(AddressOf MethodA)
Shared Dim B As Thread = New Thread(AddressOf MethodB)
Shared Dim C As Thread = New Thread(AddressOf MethodC)
Public Shared Sub Main()
A.Name = "A"
A.Start()
B.Name = "B"
B.Start()
C.Name = "C"
C.Start()
End Sub
Shared Sub MethodA()
Dim I As Integer
B.Join()
For I = 0 To 250
System.Console.Write("A")
Next
End Sub
Shared Sub MethodB()
Dim I As Integer
For I = 0 To 250
System.Console.Write("B")
Next
End Sub
Shared Sub MethodC()
Dim I As Integer
For I = 0 To 250
System.Console.Write("C")
Next
End Sub
End Class