SAMPLE: BACKGRND Demonstrates Background Processing

Last reviewed: February 15, 1996
Article ID: Q71670
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows ' versions 3.0 and 3.1

BACKGRND uses a PeekMessage() loop to do background processing. The background task is to draw rectangles at random in the application's client window. BACKGRND draws one "batch" of rectangles each time through the PeekMessage() loop, and all the rectangles in each batch are drawn in the same color. This provides a visual indication of how much background work is done before BACKGRND offers to yield.

Both the "batch size" and the total number of rectangles drawn can be changed using a menu selection.

BACKGRND does not replace the main GetMessage() loop with a PeekMessage() loop. Instead, it enters a PeekMessage() loop only when the user chooses the Draw! menu item.

While it draws the rectangles, BACKGRND displays a modeless dialog box that:

  1. Allows the user to cancel the background processing before all the rectangles have been drawn (by choosing the Cancel button)

  2. Indicates both the total number of rectangles to be drawn and the batch size

  3. Displays a "gas gauge" that indicates the percentage of the background task that has been completed

BACKGRND can be run along with another Windows-based application (for example, Notepad) to illustrate the difference between "polite" and "impolite" background processing.

If the batch size is set to a "polite" small value (for example, 10 rectangles each time through the PeekMessage loop), the user can easily type within Notepad while BACKGRND is drawing rectangles. BACKGRND draws rectangles in the spare time slices between the messages generated by the user's keystrokes, and calls PeekMessage() often enough that the user will still find Notepad responsive.

If the batch size is set to an "impolite" large value (for example, 1000 rectangles each time through the PeekMessage() loop), BACKGRND can complete its background job much more quickly, because there are fewer calls to PeekMessage() and thus less overhead. However, a user trying to type in Notepad will find the keyboard so unresponsive that Notepad will be essentially useless.

Download BACKGRND.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download BACKGRND.EXE (size: 33826 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get BACKGRND.EXE (size: 33826 bytes) 
    


Additional reference words: 3.00 3.10 softlib BACKGRND.EXE
KBCategory: kbprg kbfile
KBSubcategory: UsrMsg


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.