Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Processes
Chapter 3 - Time Manager / Using the Time Manager


Installing and Activating Tasks

Listing 3-1 shows how to install and activate a Time Manager task. It assumes that the procedure MyTask has already been defined; see Listing 3-3 and Listing 3-4 for examples of simple task definitions.

Listing 3-1 Installing and activating a Time Manager task

PROCEDURE InstallTMTask;
CONST
   kDelay = 2000;                   {delay value}
BEGIN
   gTMTask.tmAddr := @MyTask;       {get address of task}
   gTMTask.tmWakeUp := 0;           {initialize tmWakeUp}
   gTMTask.tmReserved := 0;         {initialize tmReserved}
   InsXTime(@gTMTask);              {install the task record}
   PrimeTime(@gTMTask, kDelay);     {activate the task record}
END;
In this example, InstallTMTask installs an extended Time Manager task record into the Time Manager queue and then activates the task. (The extended Time Manager task record, gTMTask, is a global variable of type TMTask.) After the specified delay has elapsed (in this case, 2000 milliseconds, or 2 seconds), the procedure MyTask runs.

In cases where no task is to run after the specified delay has elapsed, you should set the tmAddr field to NIL. To determine if the time has expired, you can check the task-active bit in the qType field.

Avoid calling PrimeTime with a Time Manager task record that has not yet expired, because the results are unpredictable. If you wish to reactivate a prior unexpired request in the Time Manager queue and specify a different delay, call RmvTime to cancel the prior request, then call InsTime to reinstall the timer task, and finally call PrimeTime to reschedule the task. Note, however, that it is possible and sometimes desirable to call PrimeTime with a Time Manager task that you want to reactivate, because the timer will have expired before the task is called.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
17 JUN 1996