Avatar of AMT_VDM
AMT_VDMFlag for Switzerland

asked on 

How to determine timespan to the milliseconds on PDAs?

I'm using C# (VS2005). Using the function GetDate.Ticks only returns me values with an accuracy of a second on an IPAQ2490.
i.e. 633082888810000000      long
or  633082888820000000      long
So this is unreliable to find out timedifferences of less than a second which is what I need to do.

Here's how I tried to implement it earlier:
            long _TicksSinceLastRead = DateTime.Now.Ticks - _lngLastReceived;

            if (_TicksSinceLastRead < _lngMinimalTimeForResponse)
                Thread.Sleep((int)(_lngMinimalTimeForResponse - _TicksSinceLastRead)/10000);

Can you provide me with code/free components I can use to get an accuracy in the milliseconds range?

Best regards
AMT_VDM
Smartphone ProgrammingWindows OS.NET Programming

Avatar of undefined
Last Comment
AMT_VDM
Avatar of dstanley9
dstanley9

What if you try comparing milliseconds instead of ticks?

DateTime dtPrevious;
DateTime dtNext;

// get previous and next dates

TimeSpan span = dtNext - dtPrevious;
long milliseconds = span.Milliseconds;

Avatar of AMT_VDM
AMT_VDM
Flag of Switzerland image

ASKER

It does not change the accuracy - here are some values:
I used your code as supplied - just did some variable renames.
            dTimeAfterSend.Millisecond      0      int
            dTimeBeforeSend.Millisecond      0      int
            span.Milliseconds      0      int
Avatar of umahesh
umahesh

Have you tried GetTickCount()
ASKER CERTIFIED SOLUTION
Avatar of checoo
checoo

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of checoo
checoo

Missed one thing you will need to replace the " throw new ApplicationException();" lines with appropriate exception or may be just put " throw new Exception();"
Avatar of AMT_VDM
AMT_VDM
Flag of Switzerland image

ASKER

Thanks for the Code Fragment, checoo - exactly what I was lookig for.

As a sidenote to complete the thread: you need to use System.Runtime.InteropServices to make use of the DLLImport Attribute - add the following line and it should work fine:

using System.Runtime.InteropServices;

Best regards
AMT_VDM
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo