Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, i write the Pocket Pc Application with Timer. ( There is no System.Time in Pocket Pc App). So I user Window Timer. i amazed 'cause there is no milliseconds and already return zero. So how do i get millisecond. Somebody said use the Environment.TickCount. But i don't know how do i use so help me if possible. :-\
Posted

The Environment.TickCount gives you the number of milliseconds that have elapsed since the system was started the number will cycle from lowest to highest value every 49.8 days so to use it.

Dim startTickCount As Int32 = Environment.TickCount

'Do something here

Dim endTickCount As Int32 = Environment.TickCount


Once you have these two values you could use the following function to determine the number of milliseconds elapsed.
VB
Public Function ElapsedMilliseconds(ByVal StartTickCount As Int32, ByVal EndTickCount As Int32) As Int32
    Dim elapsedTime As Int32 = 0
    If StartTickCount > EndTickCount Then
        elapsedTime = (Int32.MaxValue - StartTickCount) + (EndTickCount - Int32.MinValue)
    Else
        elapsedTime = EndTickCount - StartTickCount
    End If
    Return elapsedTime
End Function
 
Share this answer
 
So There is StopWatch Class in .NET FrameWork
It is Ok



VB
Dim stopWatch as new StopWatch()

Private Sub Timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
       stopWatch.Start()
   
       Dim ts As TimeSpan = stopWatch.Elapsed
       Dim elapsedTime As String = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)

        txtTimer.Text = elapsedTime
End Sub
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900