Using .NET Timers

Earlier in this chapter, we demonstrated the use of a System.Windows.Forms.Timer, and as stated there, sometimes such a timer can fit a scenario in which implementing true threading would be overkill or would introduce unwanted complexity. It is important to note that Windows Forms timers should be used only for very short tasks because they are not precise and fire on the main thread, thus influencing UI responsiveness.

Another timer available to .NET Compact Framework applications is the System.Threading.Timer. This timer is more accurate; it fires on a thread from the ThreadPool and is ideal for executing background tasks that do not touch the UI when such tasks should occur after a defined interval. The following code example ...

Get Microsoft® Mobile Development Handbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.