Imports System.Threading
public class Test
Shared Dim obj As MyClass1 = new MyClass1
public Shared Sub Main
Dim thread1 As New Thread(AddressOf doSomething)
Dim thread2 As New Thread(AddressOf doSomething)
Dim thread3 As New Thread(AddressOf doSomething)
thread1.Start()
thread2.Start()
thread3.Start()
End Sub
Private Shared Sub doSomething()
Dim i As Integer
For i = 1 To 3
obj.SharedData = i
obj.threadUniqueID = AppDomain.GetCurrentThreadId()
Console.WriteLine("ID: " & obj.threadUniqueID & ", I:=" & i & ", SharedData: " & obj.SharedData.ToString())
Thread.CurrentThread.Sleep(250)
Next
End Sub
End class
Public Class MyClass1
Public threadUniqueID As Integer
Public SharedData As Integer = 0
End Class
ID: 2564, I:=1, SharedData: 1
ID: 3196, I:=1, SharedData: 1
ID: 2656, I:=1, SharedData: 1
ID: 2564, I:=2, SharedData: 2
ID: 3196, I:=2, SharedData: 2
ID: 2656, I:=2, SharedData: 2
ID: 2564, I:=3, SharedData: 3
ID: 3196, I:=3, SharedData: 3
ID: 2656, I:=3, SharedData: 3