有谁知道System.Windows.Forms.Timer如何影响主机应用程序和系统?

时间:2021-09-24 03:16:09

Does anyone know how a System.Windows.Forms.Timer affects the host application and the system in general?

有谁知道System.Windows.Forms.Timer如何影响主机应用程序和系统?

A threaded background loop on one hand has a very high CPU usage %, whilst a Timer with a very high tick rate shows no effect in Windows Task Manager.

线程背景循环一方面具有非常高的CPU使用率%,而具有非常高的滴答速率的Timer在Windows任务管理器中显示没有效果。

Does a high tick-rate timer clutter up the Windows Message loop, or?

高速率计时器是否会使Windows消息循环混乱,或者?

2 个解决方案

#1


3  

Define "high tick rate timer" :).

定义“高滴答率计时器”:)。

The problem with timer components relying on WM_TIMER (such as the Windows.Forms one) is manifold:

定时器组件依赖于WM_TIMER(例如Windows.Forms)的问题是多方面的:

  • You will not be able to get a resolution better than 50 msec out of it, ever.
  • 你永远无法获得超过50毫秒的分辨率。

  • If your system is under load (e.g. heavy redrawing, running over RDP links, etc.) you might get WM_TIMER messages once every 500 msec or more, no matter how low you've set the interval.
  • 如果您的系统负载不足(例如重度重绘,在RDP链路上运行等),无论您设置的间隔有多低,您都可能每500毫秒或更长时间收到一次WM_TIMER消息。

  • WM_TIMER messages are synthetic messages and might not get delivered to your application at all for prolonged periods of time if your message queue gets flooded with other messages.
  • WM_TIMER消息是合成消息,如果消息队列充满其他消息,则可能无法长时间将消息传递到应用程序。

  • If your timer method takes longer than one timer interval to execute, the timer will "skip" the message, i.e. you will not get another WM_TIMER message until you've returned from the first one. In other words, you will never get two WM_TIMER messages one after the other in sequence.
  • 如果你的计时器方法需要超过一个计时器间隔来执行,计时器将“跳过”该消息,即在你从第一个返回之前你不会得到另一个WM_TIMER消息。换句话说,您将永远不会依次获得两个WM_TIMER消息。

#2


1  

Overall I have not noticed many negative downfalls to using a timer component inside my application, they are much more effective, and better on resources than some other methods out there.

总的来说,我没有注意到在我的应用程序中使用计时器组件的许多负面挫折,它们比其他一些方法更有效,并且资源更好。

I find that this Timer Comparison article from microsoft is also helpful when comparing these types of things.

我发现微软的这个Timer Comparison文章在比较这些类型的东西时也很有帮助。

But the long and short of it is that they don't appear to clutter up much.

但它的长期和短期是它们看起来并没有太多混乱。

#1


3  

Define "high tick rate timer" :).

定义“高滴答率计时器”:)。

The problem with timer components relying on WM_TIMER (such as the Windows.Forms one) is manifold:

定时器组件依赖于WM_TIMER(例如Windows.Forms)的问题是多方面的:

  • You will not be able to get a resolution better than 50 msec out of it, ever.
  • 你永远无法获得超过50毫秒的分辨率。

  • If your system is under load (e.g. heavy redrawing, running over RDP links, etc.) you might get WM_TIMER messages once every 500 msec or more, no matter how low you've set the interval.
  • 如果您的系统负载不足(例如重度重绘,在RDP链路上运行等),无论您设置的间隔有多低,您都可能每500毫秒或更长时间收到一次WM_TIMER消息。

  • WM_TIMER messages are synthetic messages and might not get delivered to your application at all for prolonged periods of time if your message queue gets flooded with other messages.
  • WM_TIMER消息是合成消息,如果消息队列充满其他消息,则可能无法长时间将消息传递到应用程序。

  • If your timer method takes longer than one timer interval to execute, the timer will "skip" the message, i.e. you will not get another WM_TIMER message until you've returned from the first one. In other words, you will never get two WM_TIMER messages one after the other in sequence.
  • 如果你的计时器方法需要超过一个计时器间隔来执行,计时器将“跳过”该消息,即在你从第一个返回之前你不会得到另一个WM_TIMER消息。换句话说,您将永远不会依次获得两个WM_TIMER消息。

#2


1  

Overall I have not noticed many negative downfalls to using a timer component inside my application, they are much more effective, and better on resources than some other methods out there.

总的来说,我没有注意到在我的应用程序中使用计时器组件的许多负面挫折,它们比其他一些方法更有效,并且资源更好。

I find that this Timer Comparison article from microsoft is also helpful when comparing these types of things.

我发现微软的这个Timer Comparison文章在比较这些类型的东西时也很有帮助。

But the long and short of it is that they don't appear to clutter up much.

但它的长期和短期是它们看起来并没有太多混乱。