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