Background Multi-tasking
     An example program

by Thomas Down

This program only works with RISC OS 3 or later

This item accompanies the article entitled Pre-emptive Multitasking with TaskWindow on page 46 of this month's RISC User magazine. The article describes how to perform time-consuming tasks as multi-tasking background operations by using the facilities of the TaskWindow module. TaskBG demonstrates some of the techniques described in the article.  It consists of a windowed front
end program (!RunImage) which displays a dialogue box on screen and
provides all the application's user interface functions, and a simple
background task (Background) which, although not a proper windowed
program, is multitasked using the TaskWindow module. This contains the
application's main code, which calculates square roots. Because this
background task is multitasked pre-emptively, it does not 'freeze' the
desktop while it is working. The two parts of the program communicate
using Wimp messages, as described in the article. Both parts of the application are commented. To examine them, simply
load them into any editor which can load BASIC programs, e.g DeskEdit or
the RISC OS 3 version of Edit.

The program can be run from the RISC User menu system, or by double-clicking on its icon in a directory viewer. A window is opened on the screen, giving brief information about the function of the program. At the top left of the window is a writable icon. Entering a value into this icon followed by a click on the OK icon at the top right will cause the background task to start calculating the square root of the value entered. To demonstrate that it is multi-tasking, the calculation is made 200000 times, during which time you can carry out other operations on the desktop in the normal way. When the calculations are finished, the result is displayed in the writable icon.

For more information on the techniques involved, you should read the accompanying article in this month's magazine.

Copyright  RISC User 1995
