VB.Net by API/System.Threading/Monitor — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 12:50, 26 мая 2010
Monitor.Enter
Imports System.Threading
Public Class MainClass
Shared Dim A As Thread = New Thread(AddressOf Method)
Shared Dim B As Thread = New Thread(AddressOf Method)
Shared Dim C As Thread = New Thread(AddressOf Method)
Shared Public MonitorLock As Object = New Object()
Public Shared Sub Main()
A.Name = "A"
A.Start()
B.Name = "B"
B.Start()
C.Name = "C"
C.Start()
End Sub
Shared Sub Method()
Thread.CurrentThread.Sleep(Int(1000 * Rnd()))
Monitor.Enter(MonitorLock)
Console.WriteLine("Thread: " & Thread.CurrentThread.Name)
Monitor.Exit(MonitorLock)
End Sub
End Class
Monitor.Exit
Imports System.Threading
Public Class MainClass
Shared Dim A As Thread = New Thread(AddressOf Method)
Shared Dim B As Thread = New Thread(AddressOf Method)
Shared Dim C As Thread = New Thread(AddressOf Method)
Shared Public MonitorLock As Object = New Object()
Public Shared Sub Main()
A.Name = "A"
A.Start()
B.Name = "B"
B.Start()
C.Name = "C"
C.Start()
End Sub
Shared Sub Method()
Thread.CurrentThread.Sleep(Int(1000 * Rnd()))
Monitor.Enter(MonitorLock)
Console.WriteLine("Thread: " & Thread.CurrentThread.Name)
Monitor.Exit(MonitorLock)
End Sub
End Class