Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/36324

From BetaArchive Wiki

HOWTO: Perform Background Processing Without Using Timers


The information in this article applies to:

  • Microsoft Windows Software Development Kit (SDK) versions 3.0, 3.1


A Windows-based application that performs a long, background task, such as repaginating a word processing document, can be designed in a number of different ways.

A polling task can be accomplished by setting a timer to fire at the desired interval. Many non-polling tasks can be performed in pieces. Although Windows does not have a method to schedule processing based on overall system load, an application can wait until there are no other messages to be processed by that application before proceeding. This article discusses the code required to implement this method.

NOTE: This polling method is unnecessary for native Win32 applications.


It is important that each piece of the task be relatively small. This allows Windows to devote processing time to other applications running in the system. Similarly, once the task is complete, it is important that the application signal that it is idle. This allows Windows to optimize its performance and to prolong battery life on portable computers.

The following code skeleton demonstrates how this might be implemented:

   do application initialization

   fBackgroundToDo = TRUE;
   fRunning = TRUE;

   while (fBackgroundToDo && fRunning)
        if (fBackgroundToDo)
             if ((PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
                  if (msg.message == WM_QUIT)
                       fRunning = FALSE;

                  fBackgroundToDo = DoABitOfBackground();
        else if ((fRunning = GetMessage(&msg, NULL, NULL, NULL)) != 0)

             fBackgroundToDo = IsThereBackgroundToDo();

For additional information on this topic, query on the following words in this Knowledge Base:


Additional query words:

Keywords : kb16bitonly kbSDKPlatform kbGrpDSUser kbWndw kbWndwMsg kbwin16sdkfaq
Issue type : kbhowto
Technology : kbAudDeveloper kbWin3xSearch kbSDKSearch kbWinSDKSearch kbWinSDK300 kbWinSDK310

Last Reviewed: December 18, 1999
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.