Chapter 14 -- Timers and Idle Processing

[Previous] [Next]

Chapter 14

Not all actions that Microsoft Windows applications undertake are performed in response to user input. Some processing is inherently time-based, such as autosave operations that save documents at 10-minute intervals and updates that involve a clock displayed in a status bar. Windows helps out by providing timers that you can program to send notifications at regular intervals. Another form of temporal processing is idle processing—work performed during "idle" periods when no messages are waiting in the message queue. MFC supplies a framework for idle-time processing in the form of a virtual function named OnIdle that is called whenever the message pump in CWinThread goes to the message queue and finds it empty.

In the first half of this chapter, we'll examine timers, which can be programmed for intervals as low as 55 milliseconds. Here are just a few of the ways in which you can put timers to use:

  • In applications that display wall-clock time. Most such applications set a timer to fire at intervals ranging from a half second to as many as 60 seconds. When a timer notification arrives, these applications update the display to reflect the current time.
  • In unattended backup programs, disk defragmenters, and other applications that lie dormant until a specified time.
  • In resource monitors, free-memory gauges, and other applications that monitor the state of the system.

In the second half of the chapter, we'll look at idle processing—what it is, how it works, and how you can use it to perform background processing tasks in MFC applications.



Programming Windows with MFC
Programming Windows with MFC, Second Edition
ISBN: 1572316950
EAN: 2147483647
Year: 1999
Pages: 101
Authors: Jeff Prosise

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net