Windows API 中有哪些定期计时器对象可用? [英] What periodic timer objects are available in the Windows API?

查看:24
本文介绍了Windows API 中有哪些定期计时器对象可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在研究比 .NET 计时器对象提供的 15 毫秒分辨率更好的选项时(参见 https://stackoverflow.com/questions/3744032/why-are-net-timers-limited-to-15-ms-resolution),我在看不同的Windows 提供的计时器对象.我已经确定了以下内容:

In researching options for getting better than the 15 ms resolution provided by .NET timer objects (see https://stackoverflow.com/questions/3744032/why-are-net-timers-limited-to-15-ms-resolution), I am looking at the different timer objects that Windows provides. I have identified the following:

Windows API 中是否有其他可用的计时器类型?

Are there other timer types available in the Windows API?

推荐答案

我问这个问题是因为我有兴趣实现一个周期性计时器,它比 .NET 提供的计时器更精细.我对这些计时器(Windows.Forms.TimerSystem.Timers.TimerSystem.Threading.Timer)的调查表明,最好的我可以希望粒度为 15 毫秒,精度为 -1 到 +30 毫秒.这适用于大多数应用程序,但不适用于我正在处理的应用程序.

I asked this question because I was interested in implementing a periodic timer that would give me better granularity than the timers that are supplied with .NET. My investigation of those timers (Windows.Forms.Timer, System.Timers.Timer, and System.Threading.Timer) shows that the best I can hope for is 15 ms granularity, and accuracy of -1 to +30 ms. That's fine for most applications, but not for the application I was working on.

有关我的调查的详细信息,请参阅为什么是 .NET计时器的分辨率限制为 15 毫秒?http://www.informit.com/guides/content.aspx?g=dotnet&seqNum=815.

For details of my investigation, see Why are .NET timers limited to 15 ms resolution? and http://www.informit.com/guides/content.aspx?g=dotnet&seqNum=815.

这促使我寻找 Windows 下可用的定期计时器对象.我确定了我在原始问题中发布的五种类型.我没有找到其他人.我丢弃了旧式 Windows 计时器,因为我不想处理消息.然后,我用 C# 为其他四种计时器类型编写了托管原型并进行了一些测试.

That led me to looking for periodic timer objects available under Windows. I identified the five types that I posted in the original question. I didn't find any others. I discarded the old-style Windows timer because I don't want to be processing messages. I then wrote managed prototypes in C# for the other four timer types and did some testing.

所有四种计时器类型(多媒体计时器、可等待计时器、计时器队列计时器和线程池计时器)都提供可靠的 1 毫秒间隔,并且具有非常好的分辨率.其中,线程池计时器是迄今为止最容易与之交互的,但不幸的是,Windows XP 不支持它.定时器队列定时器有一系列令人眼花缭乱的选项,但如果你忽略大多数选项,它们几乎和线程池定时器一样简单.有关详细信息,请参阅探索更好的计时器选项.

All four timer types (Multimedia timers, Waitable timers, Timer queue timers, and Threadpool timers) give a reliable 1 ms interval, with very good resolution. Of those, the Threadpool timer is by far the easiest to interact with, but unfortunately it's not supported on Windows XP. Timer queue timers have a dizzying array of options, but if you ignore most of the options they're almost as simple as Threadpool timers. See Exploring options for better timers for more info.

我选择在 .NET 中为我的通用计时器类包装计时器队列计时器.您可以在此处查看.

I chose to wrap the timer queue timer for my general timer class in .NET. You can see it here.

您可能还对 等待计时器感兴趣在 .NET 中使用 C#.

这篇关于Windows API 中有哪些定期计时器对象可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆