Link to home
Start Free TrialLog in
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
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

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
Have you tried GetTickCount()
ASKER CERTIFIED SOLUTION
Avatar of checoo
checoo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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