Tries to "forget" a previously scheduled Task or DTasks. This is a very powerful, but also dangerous function. An application must be sure that the task has not yet executed before calling MidiForgetTask.
pascal void MidiForgetTask (MidiEvPtr *v);
v
- is the address of a variable pointing to a previously scheduled Task or DTask but not yet executed. The variable may also contain NIL. In this case MidiForgetTask does nothing.
The variable, which address is given in parameter, is set to NIL by MidiForgetTask.
Create an infinite periodic clock (every 250ms) and stop it with MidiForgetTask.
MidiEvPtr theClock; void InfClock (long date, short refNum, long delay, long a2, long a3) { MidiSendIm (refNum, MidiNewEv(typeClock)); theClock = MidiTask (InfClock, date+delay, refNum, delay, a2, a3); } InfClock(MidiGetTime(), myRefNum, 250L, 0L, 0L); /* Start the clock */ /* Wait some time */ MidiForgetTask(&theClock); /* And forget it */
In the previous example theClock always point to a valid task because InfClock never stop by itself. If the task may decide to stop itself, it must set the pointer to NIL in order to avoid to forget an invalid task.
MidiEvPtr theClock; void CountClock (long date, short refNum, long delay,long count, long a3) { if (count > 0) { MidiSendIm (refNum, MidiNewEv(typeClock)); theClock = MidiTask (CountClock, date+delay, refNum, delay, count-1, a3); } else { theClock = NIL; /* here the task decide to stop itself, so set the pointer to NIL */ } } CountClock(MidiGetTime(), myRefNum, 250L, 100L, 0L); /* Start 100 clocks */ /* Wait some time */ MidiForgetTask(&theClock); /* And forget it */
If MidiForgetTask happens before the end of the 100 clocks, theClock points to a valid task and MidiForgetTask(&theClock) is safe. If MidiForgetTask happens after the end of the 100 clocks, theClock contains NIL and MidiForgetTask(&theClock) is safe and will do nothing.