Hello this is my first post on this Forum. I'm coming from MrExcel Forums as i started on VBA with access, i know im a noob. I have transferred to VB and SQL server but im trying to pick up a new concept to me, threading. I have looked around and found some examples but i haven't found anything that helps me understand how to use the same sub of function between multiple threads at the same time.
Can someone help me change this to work so understand how multithreading handles usage of the same function at the same time?
Can someone help me change this to work so understand how multithreading handles usage of the same function at the same time?
VB.NET:
Option Explicit On
Imports System.Threading
Imports System.ComponentModel
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim thread1 As New Thread(New ThreadStart(Sub() countup(Me.Label1)))
thread1.Start()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim thread2 As New Thread(New ThreadStart(Sub() countup(Me.Label2)))
thread2.Start()
End Sub
Private Delegate Sub CountDelegate(ByVal Label As Object)
Private Function countup(ByVal Label As Object)
countup = False
If (InvokeRequired) Then
Invoke(New CountDelegate(AddressOf countup), Label)
Else
For i = 0 To 10000
Label.Text = i.ToString
'Thread.Sleep(100)
Next
End If
countup = True
End Function
End Class