本文整理汇总了VB.NET中Microsoft.VisualBasic.Devices.Clock.TickCount属性的典型用法代码示例。如果您正苦于以下问题:VB.NET Clock.TickCount属性的具体用法?VB.NET Clock.TickCount怎么用?VB.NET Clock.TickCount使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。
在下文中一共展示了Clock.TickCount属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: LoopTask
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