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
<ThreadStatic()> Public threadUniqueID As Integer Public SharedData As Integer = 0 End Class