| Re: [aus-dotnet] TotalMilliseconds |
- From: Alex Hoffman
- Subject: Re: [aus-dotnet] TotalMilliseconds
- Date: Sat, 04 Dec 2004 12:53:31 +1100
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
You might want to consider using performance counters via interop as shown below - higher resolution than DateTime ...
using System; ...
public class Counter
{
[System.Runtime.InteropServices.DllImport("KERNEL32")]
private static extern bool QueryPerformanceCounter( ref long
lpPerformanceCount);
[System.Runtime.InteropServices.DllImport("KERNEL32")]
private static extern bool QueryPerformanceFrequency( ref long
lpFrequency);
long elapsedCount = 0;
long startCount = 0;
public void Start()
{
startCount = 0;
QueryPerformanceCounter(ref startCount);
}
public void Stop()
{
long stopCount = 0;
QueryPerformanceCounter(ref stopCount);
elapsedCount += (stopCount - startCount);
}
public void Clear()
{
elapsedCount = 0;
}
public float Seconds
{
get
{
long freq = 0;
QueryPerformanceFrequency(ref freq);
return((float) elapsedCount / (float) freq);
}
}
public override string ToString()
{
return String.Format("{0} seconds", Seconds);
}
static long Frequency
{
get
{
long freq = 0;
QueryPerformanceFrequency(ref freq);
return freq;
}
}
static long Value
{
get
{
long count = 0;
QueryPerformanceCounter(ref count);
return count;
}
}
}
Alex Hoffman
Coral Johnson said the following:
It would seem that TotalMilliseconds has an approximate resolution of 10 milliseconds. However we need to record times accurate to 1 millisecond. What is the best way of accomplishing this? Regards Coral Johnson ___________________________________________ NetLogica Pty Ltd 107 Scott St Westcourt QLD 4870, Australia Tel 07 4041 1431 Mobile 0412 706 675 Email coral.johnson@xxxxxxxxxxxxxxxx _________________ You are a part of the Australian "dotnet" mailing list. To unsubscribe send "unsubscribe dotnet" or to re-subscribe send "subscribe dotnet Your Name" in the body of the email to: imailsrv@xxxxxxxxxxx List managed by: http://www.stanski.com
_________________ You are a part of the Australian "dotnet" mailing list. To unsubscribe send "unsubscribe dotnet" or to re-subscribe send "subscribe dotnet Your Name" in the body of the email to: imailsrv@xxxxxxxxxxx List managed by: http://www.stanski.com
(Click here for more information on the aus-dotnet mailling list)
- References:
- [aus-dotnet] TotalMilliseconds, Coral Johnson
- Prev by Date: Re: [aus-dotnet] NGenerator - a simple .NET class generator.
- Next by Date: Re: [aus-dotnet] OT - IE pagesave failures
- Previous by thread: [aus-dotnet] TotalMilliseconds
- Next by thread: RE: [aus-dotnet] TotalMilliseconds
- Index(es):
