Imports System.Threading
Public Class SharedByThread
<ThreadStatic> Private Shared Count As Integer
Public Shared Sub Main()
Dim secondThread As New thread(AddressOf Thread2Proc)
secondThread.Start()
count = 100
For ctr As Integer = 0 to 10
Console.WriteLine("The value of count in the main thread is {0}.", count)
IncrementCounter(200)
Next
End Sub
Public Shared Sub Thread2Proc()
count = 0
For ctr As Integer = 0 to 10
Console.WriteLine("The value of count in the second thread is {0}.", count)
IncrementCounter(250)
Next
End Sub
Public Shared Sub IncrementCounter(delay As Integer)
count +=1
Thread.Sleep(delay)
End Sub
End Class
|