首页 / C# / c# – 节拍器使用哪个计时器类?
c# – 节拍器使用哪个计时器类?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 节拍器使用哪个计时器类?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1683字,纯文字阅读大概需要3分钟。
内容图文
![c# – 节拍器使用哪个计时器类?](/upload/InfoBanner/zyjiaocheng/810/3e99dcd40dd742c382638f0f0387f4ae.jpg)
.net框架有很多种方法可以使用计时器,但对于节拍器我应该使用哪一个?
我尝试了所有这些计时器,但没有一个对我的使用是否足够准确(他们不能在15ms以下的分辨率).
System.Windows.Forms.Timer
System.Web.UI.Timer
System.Diagnostics.Stopwatch
System.Timers.Timer
System.Threading.Timer
对于我的节拍器课程,我需要Ticks可靠,恒定,无漂移.
我发现这个实现在MSDN:https://msdn.microsoft.com/en-us/library/aa964692(v=vs.85).aspx上使用“coredll.dll”
另一种解决方案是实现这些本机方法:
[DllImport("winmm.dll", SetLastError = true, EntryPoint = "timeSetEvent")]
internal static extern UInt32 TimeSetEvent(UInt32 msDelay, UInt32 msResolution, MultimediaTimerCallback callback, ref UInt32 userCtx, UInt32 eventType);
[DllImport("winmm.dll", SetLastError = true, EntryPoint = "timeKillEvent")]
internal static extern void TimeKillEvent(UInt32 uTimerId);
在Windows上拥有分辨率低于5ms的计时器的最佳方法是什么?
编辑
我在.net(法语)中找到了关于计时器的这个非常有趣的链接:
http://www.e-naxos.com/Blog/post/NET-et-ses-timers-Prise-de-tete-ou-reelle-utilite-.aspx
解决方法:
您应该使用Multimedia Timer来实现此目的.
Multimedia timer services allow applications to schedule timer events
with the greatest resolution (or accuracy) possible for the hardware
platform. These multimedia timer services allow you to schedule timer
events at a higher resolution than other timer services.These timer services are useful for applications that demand
high-resolution timing. For example, a MIDI sequencer requires a
high-resolution timer because it must maintain the pace of MIDI events
within a resolution of 1 millisecond.
有各种C#库可供帮助使用它们.
例如:http://www.codeproject.com/Articles/5501/The-Multimedia-Timer-for-the-NET-Framework
内容总结
以上是互联网集市为您收集整理的c# – 节拍器使用哪个计时器类?全部内容,希望文章能够帮你解决c# – 节拍器使用哪个计时器类?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。