Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private qt As Queue(Of Thread)
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
qt = New Queue(Of Thread)
qt.Enqueue(New Thread(AddressOf method1))
qt.Enqueue(New Thread(AddressOf method2))
qt.Enqueue(New Thread(AddressOf method3))
qt(0).Start()
End Sub
Private Sub UpdateQueue()
qt.Dequeue()
Sync.Variable = qt.Count
End Sub
Private Sub method1()
Console.WriteLine("method1")
Thread.Sleep(3000)
UpdateQueue()
End Sub
Private Sub method2()
Console.WriteLine("method2")
Thread.Sleep(3000)
UpdateQueue()
End Sub
Private Sub method3()
Console.WriteLine("method3")
Thread.Sleep(3000)
UpdateQueue()
End Sub
Private WithEvents Sync As New SyncQueueCount
Private Sub VariableChanged(ByVal QCount As Integer) Handles Sync.VariableChanged
If QCount > 0 Then
qt(0).Start()
Else
MessageBox.Show("Queue Finished")
End If
End Sub
End Class
Public Class SyncQueueCount
Private S_Int As Integer
Public Event VariableChanged(ByVal value As Integer)
Public Property Variable() As Integer
Get
Variable = S_Int
End Get
Set(ByVal value As Integer)
S_Int = value
RaiseEvent VariableChanged(S_Int)
End Set
End Property
End Class