views:

353

answers:

2

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

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.

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

A: 

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.

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

Mitchel Sellers
+2  A: 

Define "high tick rate timer" :).

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

  • You will not be able to get a resolution better than 50 msec out of it, ever.
  • 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.
  • 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.
  • 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.
Mihai Limbășan