TERMWAIT demonstrates how to launch a child task and then wait for it
to terminate before executing specific code. Toolhelp library functions
are used for this purpose.
TERMWAIT requires 3.1 to build. However it has been compiled for
3.1 & 3.0 compatibility. TOOLHELP.DLL was not shipped with 3.0 and
consequently needs to be copied to the \windows\system directory
to run under 3.0.
TERMWAIT installs a notification call back function using NotifyRegister()
before calling WinExec() to launch the child task. All tasks in the system
will call this notification function before termination. The notification
function calls TaskFindHandle() to obtain TASKENTRY information about the
terminating task and consequently determines if the terminating task was
launched by TERMWAIT.
TERMWAIT sets the global variable bChildIsExecuting to TRUE when the child
task is spawned and sets it to FALSE after the child task has terminated.
Code that should not be executed while the child is running can check the
value of bChildIsExecuting. Menu choices that may cause rentrancy problems
during the wait should be grayed, The function AfterChildHasTerminated()
contains code that can be executed only after the child task has terminated.
If an application needs to keep track of a number of child tasks, it
can process both NFY_STARTTASK and NFY_ENDTASK in the NotifyRegister
callback function. GetCurrentTask() will return the task handle of
the task that called the notification. This information can be managed
by the parent task. Note that although no two tasks will have the same
task handle, it is possible for task handles to be reused. Consequently,
if one task terminates and another one starts, the new task can have the
same task handle as the task that just terminated. This is not a problem
if the parent task uses the NotifyRegister callback funtion to detect when
a task has terminated.