问题
I need an event to occur every 0.03125 s
The Timer control can only go to 0.031 s
How can I create an event from the Stopwatch Component which is more accurate?
回答1:
I found this, it is much more accurate and reliable than the Standard Timer! I cant believe it.
http://www.codeproject.com/Articles/5501/The-Multimedia-Timer-for-the-NET-Framework
To Quote: The Win32 multimedia timer services provide the greatest degree of timing accuracy. They allow you to schedule timing events at a higher resolution than other timer services. This can be useful in a multimedia application where timing accuracy is of utmost importance. For example, a MIDI application needs timing events that are as finely grained as possible.
Unfortunately, the Win32 multimedia timer is not part of the .NET Framework. However, by using the .NET interoperability services, the multimedia timer can be brought into the .NET fold.
回答2:
Windows is not Real-Time OS - so you can't get such guarantee for method to be executed after particular time.
The best you can do is busy wait checking for time (probably with Stopwatch) often.
You also may be able to use Multimedia timers with better resolution... (search query - c# multimedia timers, i.e. Getting accurate ticks from a timer in C#)
回答3:
Timers, in general, will only be accurate to about within 15ms, and even then, tend to have accuracy issues since they typically get pre-empted.
Having a timer with an accuracy specified in the quarter of a millisecond range will require a real time operating system, and is likely not going to work properly, no matter which timer is used.
回答4:
'I need an event to occur every 0.03125 s' - to reliably achieve such precision, use a dedicated microcontroller.
You cannot achieve what you seem to need on a desktop OS.
回答5:
How about high priority thread and loop with chek stopwatch time or some more accurate counter?
来源:https://stackoverflow.com/questions/10605639/timer-component-not-accurate-enough-is-there-an-alternative