Compact Framework - getting clock tick for device

Posted on 2009-02-11
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

Question by:AgentDigby
    LVL 24

    Accepted Solution

    Environment.TickCount gives you the timer ticks

    some unrelated samples are e.g. here:


    Author Closing Comment

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

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Join & Write a Comment

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now