本文整理汇总了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