What is the best way to measure time in .NET cf? I currently use:
DateTime start = DateTime.Now;
// Do some work
double elapsed = (DateTime.Now - start).TotalMilliseconds;
This doesn't seem to work very well, as it always returns 0.0 or 1000.0. I
need a better measurement. Any suggestions?
Thanks in advance!
Nille
--
Alex Feinman
---
Visit http://www.opennetcf.org
"Nille" <Ni...@discussions.microsoft.com> wrote in message
news:2F68AE33-F5C8-47CB...@microsoft.com...
Nille
Best of all though is to use the Stopwatch class. Its story and dll is here:
http://www.danielmoth.com/Blog/2004/12/stopwatch.html
The above link also includes the VB source. The C# (identical) version is
here:
http://www.opennetcf.org/sourcebrowse/view.aspx?f=d:/sites/OpenNETCF/InetPub/wwwroot/Source/OpenNETCF/Diagnostics/Stopwatch.cs
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
"Nille" <Ni...@discussions.microsoft.com> wrote in message
news:2F68AE33-F5C8-47CB...@microsoft.com...
So to be totally correct, assuming my assumptions were correct (and that's a
lot of assuming) then the milliseconds member of the DateTime returned by
properties such as Now is dependent on the OEM implementation of the
SystemTime and is very often not implemented, which means that it is most
often useless and one should use Environmet.Tickcount to get time spans.
However if you need an actual millisecond resolution time for something like
data logging, check with your OEM, it may in fact be possible.
I just had to put that out there because it seems that lately I've been
getting called out on exceptions to the rule (like USB Host not being
available on Pocket PC) and because I know you can take it. :)
-Chris
"Alex Feinman [MVP]" <publi...@alexfeinman.com> wrote in message
news:%23q85Yls...@tk2msftngp13.phx.gbl...
[DllImport("coredll.dll")]
public static extern int QueryPerformanceCounter(ref double Counter);
[DllImport("coredll.dll")]
public static extern int QueryPerformanceFrequency(ref double Frequency);
double BeginTime = 0;
double EndTime = 0;
double Frequency = 0;
double Elapsed = 0;
QueryPerformanceFrequency(ref Frequency);
QueryPerformanceCounter(ref BeginTime);
//Do Something
QueryPerformanceCounter(ref EndTime);
Elapsed = (EndTime - BeginTime) / Frequency;
Hope this helps!
Louis-Pierre Beaumont