First off, you need to realize that it's extremely difficult, if not impossible, to do exact timing on a computer because of limitations exposed both by the hardware and software. The good news is that this kind of precision is rarely necessary. Ten ticks is an insanely small amount of time. Very little work is getting done by the CPU in this interval, and it's never going to be statistically significant.
For reference, the Windows clock has an accuracy of around 10 milliseconds (less on earlier versions). Wrapping your code with calls to DateTime.UtcNow
isn't going to do any better than that.
In your question, you talk about wanting to "raise an event." The problem is that the only type of time-keeping object that raises an event at specific intervals is the Timer
object. It's available in 3 different incarnations in the .NET Framework (System.Timers.Timer
, System.Threading.Timer
, and System.Windows.Forms.Timer
), all of which have their own unique use scenarios and relative quirks, but none of them guarantee precision anywhere close to what you're asking for. They're not even designed to do so, and neither are there any equivalent functions exposed by the Windows API that are going to provide this type of precision.
The reason I asked why you were wanting to do this and if you're attempting to benchmark is because that changes the entire game. The .NET Framework (as of version 2.0) provides a Stopwatch
object that is expressly designed to accurately measure elapsed time for a situation like benchmarking or performance profiling. The Stopwatch
simply wraps the Windows API functions QueryPerformanceFrequency
and QueryPerformanceCounter
(which should confirm my suggestion as to its intended use). We used to have to P/Invoke these functions to access this type of functionality in earlier versions of the Framework, but it's now conveniently built in. If you need a timer with a relatively high resolution for benchmarking, the Stopwatch
is your best bet. In theory, it can provide you with sub-microsecond timing.
But it's not without its problems. It doesn't raise any events, so if your current design relies on event handling, you're going to have to rethink it. And, it's not guaranteed to be perfectly accurate, either. Sure, it may have the highest possible resolution given hardware constraints, but that doesn't mean it will necessarily meet your stated requirements. For example, it may be unreliable on a multiple processor system where Start
and Stop
have to be executed on the same processor. It shouldn't matter, but it does. It's also subject to being unreliable on processors that can throttle their clock speed up and down. And dare I even mention that the call to QueryPerformanceCounter
itself is going to take some time—about 5 microseconds even on a modern 2+ GHz processor, which prevents you from actually being able to achieve that sub-microsecond timing that sounded good in theory. Then again, any reasonable code profiler would consider that amount of time negligible because, well, it is.
(See also: http://www.devsource.com/c/a/Techniques/High-Performance-Timing-under-Windows/2/)