• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 941
  • Last Modified:

Compact Framework - getting clock tick for device

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

1 Solution
Environment.TickCount gives you the timer ticks

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

AgentDigbyAuthor Commented:
Thanks - for ever in your debt!
Worth staying up for - it really works...
A million thanks.

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now