Gets the millisecond count from the computer's system timer.
' Usage Dim value As Integer = My.Computer.Clock.TickCount ' Declaration Public ReadOnly Property TickCount As Integer
The TickCount property provides access to the computer's system timer, which runs when the computer is active. The timer resolution is not less than 500 milliseconds.
You can use this property to make your application's behavior dependent on the length of time it has been running, or you can use it to label events, both of which are independent of the computer's clock.
If the computer runs continuously, TickCount increments from zero to the maximum integer value in approximately 24.9 days.
The TickCount property increments only when the operating system is running; it pauses when the computer goes into certain power-saving modes, such as standby or hibernation. The TickCount property is unrelated to the computer's clock setting.
The My.Computer.Clock.TickCount property has the same behavior as the Environment.TickCount property.
The following example uses the My.Computer.Clock.TickCount property to run a task in a loop for a given number of seconds, even if the computer's system time changes while it runs.
Public Sub LoopTask(ByVal secondsToRun As Integer) Dim startTicks As Integer = My.Computer.Clock.TickCount Do While IsTimeUp(startTicks, secondsToRun) ' Code to run for at least secondsToRun seconds goes here. Loop End Sub Private Function IsTimeUp( _ ByVal startTicks As Integer, _ ByVal seconds As Integer _ ) As Boolean ' This function throws an overflow exception if the ' tick count difference is greater than 2,147,483,647, ' about 24 days for My.Computer.Clock.TickCount. ' Use UInteger to simplify the code for roll over. Dim uStart As UInteger = _ CUInt(CLng(startTicks) - Integer.MinValue) Dim uCurrent As UInteger = _ CUInt(CLng(My.Computer.Clock.TickCount) - Integer.MinValue) ' Calculate the tick count difference. Dim tickCountDifference As UInteger If uStart <= uCurrent Then tickCountDifference = uCurrent - uStart Else ' Tick count rolled over. tickCountDifference = UInteger.MaxValue - (uStart - uCurrent) End If ' Convert seconds to milliseconds and compare. Return CInt(tickCountDifference) < (seconds * 1000) End Function
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
Availability by Project Type
Windows Control Library
Web Control Library