本文整理匯總了VB.NET中System.Threading.AutoResetEvent.AutoResetEvent構造函數的典型用法代碼示例。如果您正苦於以下問題:VB.NET AutoResetEvent構造函數的具體用法?VB.NET AutoResetEvent怎麽用?VB.NET AutoResetEvent使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在類System.Threading.AutoResetEvent
的用法示例。
在下文中一共展示了AutoResetEvent構造函數的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Main
' 導入命名空間
Imports System.Threading
Namespace AutoResetEvent_Examples
Class MyMainClass
'Initially not signaled.
Private Const numIterations As Integer = 100
Private Shared myResetEvent As New AutoResetEvent(False)
Private Shared number As Integer
<MTAThread> _
Shared Sub Main()
'Create and start the reader thread.
Dim myReaderThread As New Thread(AddressOf MyReadThreadProc)
myReaderThread.Name = "ReaderThread"
myReaderThread.Start()
Dim i As Integer
For i = 1 To numIterations
Console.WriteLine("Writer thread writing value: {0}", i)
number = i
'Signal that a value has been written.
myResetEvent.Set()
'Give the Reader thread an opportunity to act.
Thread.Sleep(1)
Next i
'Terminate the reader thread.
myReaderThread.Abort()
End Sub
Shared Sub MyReadThreadProc()
While True
'The value will not be read until the writer has written
' at least once since the last read.
myResetEvent.WaitOne()
Console.WriteLine("{0} reading value: {1}", Thread.CurrentThread.Name, number)
End While
End Sub
End Class
End Namespace 'AutoResetEvent_Examples