本文整理匯總了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.