Important: The information in this document is obsolete and should not be used for new development.
Installing and Activating Tasks
Listing 3-1 shows how to install and activate a Time Manager task. It assumes that the procedureMyTask
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 typeTMTask
.) After the specified delay has elapsed (in this case, 2000 milliseconds, or 2 seconds), the procedureMyTask
runs.In cases where no task is to run after the specified delay has elapsed, you should set the
tmAddr
field toNIL
. To determine if the time has expired, you can check the task-active bit in theqType
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, callRmvTime
to cancel the prior request, then callInsTime
to reinstall the timer task, and finally callPrimeTime
to reschedule the task. Note, however, that it is possible and sometimes desirable to callPrimeTime
with a Time Manager task that you want to reactivate, because the timer will have expired before the task is called.