We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Compact Framework - getting clock tick for device

Medium Priority
Last Modified: 2013-11-18
Can Anybody Help?
I need to get the low level clock ticks for a timing program on the Pocket PC - I am using VB.Net 2005. I have found this article on MSDN:
As you can see it refers to devices in the address and one supposes that it is "what it says on the tin".
However, when placing the example code from this page onto the PPC emulation in Visual Studio (VB) I get the message:
" 'Computer' is not a member of My "
It seems as if Microsoft has an unexplained contradiction in that "My.Computer" is not part of the Compact Framework but is issuing code that includes "My.Computer"
You can get the code from the link but I have dropped it n below...I think the code is for non compact framework and Microsoft have goofed - or I have!
Can anyone suggest anything? I know it can be done as a one time colleague got it working in embedded VB.

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.
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
        ' Tick count rolled over.
        tickCountDifference = UInteger.MaxValue - (uStart - uCurrent)
    End If
    ' Convert seconds to milliseconds and compare.
    Return CInt(tickCountDifference) < (seconds * 1000)
End Function

Open in new window

Watch Question

Environment.TickCount gives you the timer ticks

some unrelated samples are e.g. here: http://stackoverflow.com/questions/243351/environment-tickcount-vs-datetime-now

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Thanks - for ever in your debt!
Worth staying up for - it really works...
A million thanks.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.