I'm making a simple multithreading program to explain the working of threading. I want two counters counting on the same time but it doesn't work.
It only works if I use: CheckForIllegalCrossThreadCalls = False. But, I want to program in a proper way.
Code:
Dim Thread1 As System.Threading.Thread Dim Thread2 As System.Threading.Thread Private Delegate Sub SetTeller1() Private Sub teller1() If teller1Label.InvokeRequired Then Invoke(New SetTeller1(AddressOf teller1)) Else For i As Integer = 0 To 1000 teller1Label.Text = i Refresh() Next End If End Sub Delegate Sub SetTeller2() Private Sub teller2() If teller2Label.InvokeRequired Then Invoke(New SetTeller2(AddressOf teller2)) Else For i As Integer = 0 To 1000 teller2Label.Text = i Refresh() Next End If End Sub Private Sub teller1Button_Click(sender As Object, e As EventArgs) Handles teller1Button.Click Thread1 = New Threading.Thread(AddressOf teller1) Thread1.Start() End Sub Private Sub teller2Button_Click(sender As Object, e As EventArgs) Handles teller2Button.Click Thread2 = New Threading.Thread(AddressOf teller2) Thread2.Start() End Sub