11

i want a real time clock with precision of microseconds how can i do so?

is there any real time clock other than stopwatch;

2
  • 9
    Why "other than stopwatch"? Isn't that like asking, "I want to store a string. Is there a string type other than string?" Commented May 10, 2010 at 6:25
  • possible duplicate of Can Stopwatch be used in production code? Commented May 10, 2010 at 18:48

7 Answers 7

16

You want System.Diagnostics.Stopwatch, which can measure time intervals accurately to the microsecond (depending on hardware limitations).

Sign up to request clarification or add additional context in comments.

Comments

7

System.Diagnostics.Stopwatch uses the QueryPerformanceCounter and QueryPerformanceFrequency Windows APIs. The resolution is not standard across machines, but generally it's on the order of microseconds (see this KB article for more info).

In Vista/Win7 there is also QueryProcessCycleTime and QueryThreadCycleTime which will give you the number of elapsed cycles for your process/thread. This is useful if you want to know only the active time for the process (e.g. time when you weren't switched-out).

Comments

4

The most precise timer available in .NET is StopWatch.

Comments

3

For a high resolution measurements you could use the QueryPerformanceCounter function:

class Program { [DllImport("kernel32.dll")] private static extern void QueryPerformanceCounter(ref long ticks); static void Main() { long startTicks = 0L; QueryPerformanceCounter(ref startTicks); // some task long endTicks = 0L; QueryPerformanceCounter(ref endTicks); long res = endTicks - startTicks; } } 

2 Comments

This is equivalent to the functionality in System.Diagnostics.Stopwatch.
Chris is right. The Stopwatch uses the kernel32 QueryPerformanceCounter below the covers, so there is no reason for using this code (when using .NET 2.0 or up). This code is still useful for those poor souls still working with .NET 1.1.
2

check this http://www.c-sharpcorner.com/UploadFile/kapilsoni88/Digital_Click08142008142713PM/Digital_Click.aspx and also check this http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx

Comments

0

If you want a good time mesurement I think csharp as an high level language might not be a good idea. you could assemble a simple program that taps to RTC and then tie it to your program via a library. That is literally the best possible scenario you can get whith no Object overhang, but it requires some low level know how to put together.

Comments

0

If you have no internet access and you want real time for timed trial license of software then you can use USB dongle with Real time clock.

Its time calculation is driven by an internal clock which is battery-driven. You can access the time from USB dongle using API functions which come along with these types of dongles.

EX-http://www.senselock-europe.com/en/elite-el-rtc-dongle.html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.