本文整理汇总了VB.NET中System.Timers.Timer.AutoReset属性的典型用法代码示例。如果您正苦于以下问题:VB.NET Timer.AutoReset属性的具体用法?VB.NET Timer.AutoReset怎么用?VB.NET Timer.AutoReset使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Timers.Timer
的用法示例。
在下文中一共展示了Timer.AutoReset属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Timers
Public Module Example
Private aTimer As System.Timers.Timer
Public Sub Main()
' Create a timer with a 1.5 second interval.
Dim interval As Double = 1500.0
aTimer = New System.Timers.Timer(interval)
' Hook up the event handler for the Elapsed event.
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
' Only raise the event the first time Interval elapses.
aTimer.AutoReset = False
aTimer.Enabled = True
' Ensure the event fires before the exit message appears.
System.Threading.Thread.Sleep(CInt(interval * 2))
Console.WriteLine("Press the Enter key to exit the program.")
Console.ReadLine()
' If the timer is declared in a long-running method, use
' KeepAlive to prevent garbage collection from occurring
' before the method ends.
'GC.KeepAlive(aTimer)
End Sub
' Specify what you want to happen when the Elapsed event is
' raised.
Private Sub OnTimedEvent(source As Object, e As ElapsedEventArgs)
Console.WriteLine("Hello World!")
End Sub
End Module
输出:
Hello World! Press the Enter key to exit the program.