当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET Clock.TickCount属性代码示例

本文整理汇总了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
开发者ID:VB.NET开发者,项目名称:Microsoft.VisualBasic.Devices,代码行数:33,代码来源:Clock.TickCount


注:本文中的Microsoft.VisualBasic.Devices.Clock.TickCount属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。