How do I get an accurate time in CF?

  • Thread starter Thread starter Jim H
  • Start date Start date
J

Jim H

I need to keep the time with data that is coming into my app. On the
desktop I use DateTime.Now.Ticks to get a time stamp down to the thousandths
of a second. On the desktop is gave me numbers like this:
632312367562450276
632312367562606512

On the PPC I get numbers like this:
632314491430000000
632314491500000000

The precision is not there. The numbers I get from the PPC have gaps
anywhere from 2 to 5 seconds. The gaps on the desktop are approx .015
seconds. Is there a way to get a more accurate time stamp from PPC?

Thanks,
jim
 
"Gaps" I'm not sure about but, as you know, the hardware inside a PPC is not
the same as the hardware inside a PC, including timers. If you P/Invoke to
GetTickCount(), that will return a number of timer ticks since startup.
Since it's a 32-bit value, it will roll over periodically and you'll have to
handle that, but it should give you one tick per ms (0.001). It's possible
that QueryPerformanceCounter() would also work on PPC (I don't have any PPC
devices to try it). That might give you a higher-resolution counter.

What is it that you are trying to do with this time? Calculate a really
accurate time-of-day? Or measure a delta between two events?

Paul T.
 
I'm trying to measure between 2 events. I'm reading from a connection and I
need to record the time between the packets of data I get back.

DateTime.Now.Ticks is supposed to be the tick count. According to the
documentation:
The value of this property is the number of 100-nanosecond intervals that
have elapsed since 12:00 A.M., January 1, 0001.

But the values coming back from the PPC seem to only be accurate to the ten
millions. All the numbers that came back had 7 0's after them. No number
was any more accurate than that.

Thanks,
jim
 
While Ticks are in 100 ns units, actual resolution depends on hardware and
is about 50 ms in most cases.

You can P/Invoke this to get higher precision:

[DllImport("coredll.dll")]
private static extern bool QueryPerformanceCounter(out long count);

[DllImport("coredll.dll")]
private static extern bool QueryPerformanceFrequency(out long
frequency);

This is optional, but implemented on most PPC. Resolution is usually 1 uS.
Call QueryPerformanceFrequency() first to make sure it's implemented and to
find out the actual resolution.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
Environment.TickCount is what you want. The Perf counters can give even
higher resolution.

-Chris
 
Back
Top