窗口最小化时.NET Timer 控件运行速度更快

发布于 2024-08-19 20:29:31 字数 114 浏览 9 评论 0原文

这实际上是一个明显的差异,我已经看到但无法解释。这些计时器的间隔设置为 1 毫秒(可用的最低值),但虽然它被最小化,但它似乎滴答得更快?谁能给我解释一下这个现象吗?如果可能的话,解释一下如何在窗口最大化时重现效果?

It's actually a noticeable difference that I've seen but cannot explain. These timers have intervals set to 1ms (the lowest available), but while it's minimized, it seems to tick faster? Could anyone explain this phenomenon to me? And if possible, explain how to reproduce the effect while the window is maximized?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱已欠费 2024-08-26 20:29:31

这是一个 Forms.Timer 吗?

我怀疑它运行得更快,更有可能是计时器触发事件​​得到了更及时的处理。虽然最小化,但表单窗口的消息泵处理的消息可能会减少,这可能会占用更大的时间片来处理计时器消息。还有最小定时器分辨率的问题。

如果适用,请尝试使用其他计时器类型之一,例如 System.Timers

Windows 窗体计时器组件是
单线程,并且仅限于
精度为55毫秒。如果你
需要一个多线程定时器
更高的准确性,使用 Timer 类
在 System.Timers 命名空间中。

参考

Is this a Forms.Timer?

I doubt it is running faster, more likely that the Timer firing event is being handled in a more timely manner. Whilst minimised there will presumably be less messages handled by the Form windows's message pump, which could account for a larger time slice to handle the Timer messages. There is also the isue of the minimum Timer resolution.

If applicable, try using one of the other Timer types, such as System.Timers

The Windows Forms Timer component is
single-threaded, and is limited to an
accuracy of 55 milliseconds. If you
require a multithreaded timer with
greater accuracy, use the Timer class
in the System.Timers namespace.

Ref.

稳稳的幸福 2024-08-26 20:29:31

如果我没记错的话,您可以从 System.Windows.Forms.Timer 中获得的最小分辨率(我假设您在这里使用的是它)是 55 毫秒。将其设置为 1 毫秒本质上意味着它会连续滴答。

当然,计时器并不能保证刻度会准确地按照指定的时间间隔到达。如果您的应用程序正忙于执行其他操作(例如重绘屏幕),那么可能会花费更多的时间,或者在重负载下需要更多的时间。如果计时器设置为 1 秒的间隔,您不会真正注意到这一点,但在最小窗口(55 毫秒)下,您可能会注意到。

当应用程序最小化时,在计时器事件触发之前可以中断计时器事件的其他事件就会减少。

If I remember correctly, the minimum resolution you can get out of a System.Windows.Forms.Timer (which I assume is what you're using here) is 55 ms. Setting it to 1 ms essentially means that it ticks continuously.

Of course, a timer doesn't guarantee that ticks will arrive at exactly the interval specified. If your app is busy doing other things (like redrawing the screen) then it may take a few more ms, or significantly more under heavy load. If the timer is set to an interval of 1 second, you won't really notice this, but at the minimum window (55 ms), you might.

When the application is minimized, there are fewer other events that can interrupt the timer events before they fire.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文