本文整理匯總了VB.NET中System.Timers.Timer.Interval屬性的典型用法代碼示例。如果您正苦於以下問題:VB.NET Timer.Interval屬性的具體用法?VB.NET Timer.Interval怎麽用?VB.NET Timer.Interval使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Timers.Timer
的用法示例。
在下文中一共展示了Timer.Interval屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
' 導入命名空間
Imports System.Timers
Public Module Example
Private aTimer As Timer
Public Sub Main()
' Create a timer and set a two second interval.
aTimer = New System.Timers.Timer()
aTimer.Interval = 2000
' Hook up the Elapsed event for the timer.
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
' Have the timer fire repeated events (true is the default)
aTimer.AutoReset = True
' Start the timer
aTimer.Enabled = True
Console.WriteLine("Press the Enter key to exit the program at any time... ")
Console.ReadLine()
End Sub
Private Sub OnTimedEvent(source As Object, e As System.Timers.ElapsedEventArgs)
Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime)
End Sub
End Module
輸出:
Press the Enter key to exit the program at any time... The Elapsed event was raised at 5/20/2015 8:48:58 PM The Elapsed event was raised at 5/20/2015 8:49:00 PM The Elapsed event was raised at 5/20/2015 8:49:02 PM The Elapsed event was raised at 5/20/2015 8:49:04 PM The Elapsed event was raised at 5/20/2015 8:49:06 PM
示例2: Example
' 導入命名空間
Imports System.Collections.Generic
Imports System.IO
Imports System.Timers
Module Example
Private WithEvents aTimer As Timer
Private eventlog As List(Of String)
Private nEventsFired As Integer = 0
Private previousTime As Date
Public Sub Main()
eventlog = New List(Of String)()
Dim sr As New StreamWriter(".\Interval.txt")
' Create a timer with a five millisecond interval.
aTimer = New Timer(5)
aTimer.AutoReset = True
sr.WriteLine("The timer should fire every {0} milliseconds.",
aTimer.Interval)
aTimer.Enabled = True
Console.WriteLine("Press the Enter key to exit the program... ")
Console.ReadLine()
For Each item In eventlog
sr.WriteLine(item)
Next
sr.Close()
Console.WriteLine("Terminating the application...")
End Sub
Private Sub OnTimedEvent(source As Object, e As ElapsedEventArgs) _
Handles aTimer.Elapsed
eventlog.Add(String.Format("Elapsed event at {0:HH':'mm':'ss.ffffff} ({1})",
e.SignalTime,
If(nEventsFired = 0,
0.0, (e.SignalTime - previousTime).TotalMilliseconds)))
nEventsFired += 1
previousTime = e.SignalTime
if nEventsFired = 20 Then
Console.WriteLine("No more events will fire...")
aTimer.Enabled = False
End If
End Sub
End Module
輸出:
The timer should fire every 5 milliseconds. Elapsed event at 08:42:49.370344 (0) Elapsed event at 08:42:49.385345 (15.0015) Elapsed event at 08:42:49.400347 (15.0015) Elapsed event at 08:42:49.415348 (15.0015) Elapsed event at 08:42:49.430350 (15.0015) Elapsed event at 08:42:49.445351 (15.0015) Elapsed event at 08:42:49.465353 (20.002) Elapsed event at 08:42:49.480355 (15.0015) Elapsed event at 08:42:49.495356 (15.0015) Elapsed event at 08:42:49.510358 (15.0015) Elapsed event at 08:42:49.525359 (15.0015) Elapsed event at 08:42:49.540361 (15.0015) Elapsed event at 08:42:49.555362 (15.0015) Elapsed event at 08:42:49.570364 (15.0015) Elapsed event at 08:42:49.585365 (15.0015) Elapsed event at 08:42:49.605367 (20.002) Elapsed event at 08:42:49.620369 (15.0015) Elapsed event at 08:42:49.635370 (15.0015) Elapsed event at 08:42:49.650372 (15.0015) Elapsed event at 08:42:49.665373 (15.0015)
示例3: Main
Module Example
Private Declare Function GetSystemTimeAdjustment Lib "Kernel32" (
ByRef lpTimeAdjustment As Long, ByRef lpTimeIncrement As Long,
ByRef lpTimeAdjustmentDisabled As Boolean) As Boolean
Public Sub Main()
Dim timeAdjustment, timeIncrement As Long
Dim timeAdjustmentDisabled As Boolean
If GetSystemTimeAdjustment(timeAdjustment, timeIncrement,
timeAdjustmentDisabled) Then
If Not timeAdjustmentDisabled Then
Console.WriteLine("System clock resolution: {0:N3} milliseconds",
timeIncrement/10000.0)
Else
Console.WriteLine("Unable to determine system clock resolution.")
End If
End If
End Sub
End Module
輸出:
System clock resolution: 15.625 milliseconds