Wait Until Task Is Finished

Tasks Block

Description

This block does not allow the program to continue until all of the enclosed tasks have finished. A Task is a procedure that has been started to run on its own with a Begin Task block. There can be one or several procedure names indicated inside the Wait Until Task Is Finished block. When inside this block the procedure blocks are not executed but are instead checked for task completion status. The check is performed every controller sample. Only procedure blocks should be placed inside. The order of the blocks inside does not matter.

Escapes

The Wait Until Task Is Finished block does not generate any escapes.

Examples

Consider an application that has these two procedures for moving two motors back and forth different distances and a different number of times.

These activities need to start at the same time. A notification is required when they are both done. It is likely one will finish before the other but it is not clear which one will finish first. This procedure could manage those independent activities.

The same behavior could be achieved by doing this:

There is a difference between the two if it is necessary to abort the wave procedures early. A task's identity is the name of the procedure that started it. For a block that is started with Begin Task its identify is its own name such as "Wave_Axis_1" or "Wave_Axis_2" which is the case in the first example. In the first example this block list could be terminated by this button click procedure:

The tasks sustaining the motion would be immediately stopped. The motors would finish their current moves since only the task had been aborted, not the motion. To stop the motion as well motion blocks would need to be appended:

However in the second case where "Wave_Axis_2" is inline and not in the Begin Task block it is not operating under the name "Wave_Axis_2". Since it is being procedurally called it is part of the procedure that called it and operating under that procedure's name or possibly another name depending on how that procedure was called. Aborting "Wave_Axis_2" will have no effect. To preserve the option of aborting a task it must run under a known name. To achieve the blocking effect of a procedure call then requires starting the task and waiting for it to finish:

Note that if an exception occurs within "Abortable_Process" that it does not escape into this click procedure. Independent processes must trap their own exceptions.

Related Topics

Begin Task
Abort Task
Try Recover