💾 Archived View for blitter.com › apl-books › APLX50 › APLX-manual › www.microapl.com › apl_help › c… captured on 2023-01-29 at 14:38:15.
⬅️ Previous capture (2022-07-17)
-=-=-=-=-=-=-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Using the child task</TITLE> <META NAME="DESCRIPTION" CONTENT="APL language help page: Using the child task"> <META NAME="KEYWORDS" CONTENT="Multi-tasking,Tasks,Child Tasks,apl,aplx,apl help"> <!-- %%COMMON_HEAD%% --> <META http-equiv="Content-Type" content="text/html; charset=utf-8"> <LINK rel="stylesheet" type="text/css" href="http://www.microapl.com/styles_apl_help.css"> <!-- %%END%%--> </HEAD> <body> <table> <tr> <td width="800" valign="top" colspan="2"> <center>Topic: <A HREF="ch.htm"><code>APLX Help</code></A> : <A HREF="ch_200.htm"><code>Multi-tasking support</code></A> : <A HREF="ch_200_040.htm"><code>Using the child task</code></A> </center> <center> [ <A HREF="ch_200_030.htm">Previous</A> | <A HREF="ch_200_050.htm">Next</A> | <A HREF="ch.htm">Contents</A> | <A HREF="help_index.htm">Index</A> | <A HREF="http://www.microapl.co.uk/apl/index.html">APL Home</A> ]</center> <br></td> </tr> <tr> <td width="120"> <a href="http://www.microapl.co.uk/apl/index.html"><img height="68" border="0" width="119" src="MicroAPL_logo.gif" alt="www.microapl.co.uk"></a> </td> <td align="left" valign="bottom"> <h1>Using the child task</h1> </td> </tr> <tr> <td width="800" valign="top" colspan="2"> <hr> <p>If the child task has a visible session window associated with it, you can enter commands and APL expressions in it in the normal way. Alternatively, the parent APL task can use it as follows:</p> <H3>Checking the status of the child task:</H3> <p>The <tt>status</tt> read-only property indicates the execution state of the task. It returns one of the following codes:</p> <p><code> ¯1 </code>The task is not running (i.e. it has not been opened, or has terminated)</p> <p><code> 0 </code>The task is busy executing an APL expression or command</p> <p><code> 1 </code>The task is in desk-calculator mode, awaiting input</p> <p><code> 2 </code>The task is awaiting <code>⍞</code> input</p> <p><code> 3 </code>The task is awaiting <code>⎕</code> input</p> <p><code> 4 </code>The task is awaiting <code>⎕CC</code> input</p> <H3>Causing the child task to execute an expression or command</H3> <p>The <tt>Execute</tt> method allows the parent to cause the child task to execute an APL expression or system command. It takes as an argument a character string which the command to be executed (or passed as input to <code>⍞</code> or <code>⎕)</code>.</p> <p>The child task should be awaiting input (you can tell whether this is the case by reading the <A HREF="ch_030_030_0825.htm"><tt>status</tt></a> property, or by using the <A HREF="ch_030_050_0338.htm"><tt>onReady</tt></A> callback). If it is not, the command will be placed in a buffer and will be executed when the child task next asks for input. However, there is no queue of commands held; any existing command already in the buffer will be over-written if the child task has not yet executed it. The <tt>Execute</tt> method returns immediately; it does not wait for the command to complete.</p> <p>In this example, the child task is initially ready for input. It then executes the )LOAD command, and is busy for a short time (<tt>status</tt> property is 0). The <tt>status</tt> property then changes back to 1 when it is ready for further input:</p> <pre> ChildTask.status 1 ChildTask.Execute ')LOAD 10 SAMPLEEXCEL' ChildTask.status 0 ChildTask.status 1 </pre> <p>Note that in a real multi-tasking APLX application you would typically use 'signal' events to allow the parent and child tasks to communicate with each other and synchronize their operations - this is described below. The <tt>Execute</tt> method would typically be used only when starting up the child task. </p> <H3>Reading back the child task's session window contents</H3> <p>The <tt>text</tt> property of the APL object contains the text in the task's session window (assuming it is not a background task). For example, after executing the )LOAD above you might have:</p> <pre> CONTENTS←ChildTask.text CONTENTS CLEAR WS )LOAD 10 SAMPLEEXCEL SAVED 2002-09-12 16.43.21 APLX for Windows and Excel Sample - 18th July 2002 -------------------------------------------------- This workspace contains some functions to demonstrate how to use APLX to access Excel spreadsheets via the Microsoft Excel OLE server.</pre> <p><i>... etc</i></p> <p>It is a text vector, usually with embedded carriage return (<code>⎕R</code>) characters. The <tt>text</tt> property returns the logical contents of the session window, even if the session window is not visible (however it is always an empty vector for a background task, which does not have a session window). You can also write to this property to change the text in the session window of a child task.</p> <H3>Uniquely identifying a child task</H3> <p>Every task has a unique identifier. You can read the task identifier of a child task using the read-only <tt>taskid</tt> property. It is a scalar integer, and can be used in event handling to identify the task:</p> <pre> ChildTask.taskid 53429272 </pre> <p>The <tt>taskid</tt> property will be zero if the task is not running.</p> <p>The child task can read its own task identifier using the <tt>taskid</tt> property of its System object.</p> <H3>Interrupting a child task under program control</H3> <p>If a child task is executing (<tt>status</tt> property is 0), the <tt>Interrupt</tt> method can be called to interrupt it. It is equivalent to a keyboard interrupt (break).</p> <H3>Terminating a child task under program control</H3> <p>A child task may terminate for various reasons. For example, you might use the <tt>Execute</tt> method to cause it to execute an <code>)OFF</code> command, or it may run an APL function which ends by executing an <code>)OFF</code>. If it has a session window, you can end the task in the same ways as you would a top-level task, using the File menu or by closing the session window.</p> <p>Alternatively, a parent task can terminate the child by using the <tt>Close</tt> method:</p> <pre> ChildTask.Close </pre> <p>This closes any windows belonging to the task, releases the workspace memory, and ends the task. The <tt>status</tt> property reverts to <code>¯1</code>. If you wish you can then use the <tt>Open</tt> method to start it afresh, or the <tt>Delete</tt> method to destroy the task object altogether (or erase the last reference to it in the workspace).</p> <p>If a parent task terminates, all its child tasks are automatically terminated as well.</p> <hr> </td> </tr> <tr> <td width="800" valign="top" colspan="2"> <center>Topic: <A HREF="ch.htm"><code>APLX Help</code></A> : <A HREF="ch_200.htm"><code>Multi-tasking support</code></A> : <A HREF="ch_200_040.htm"><code>Using the child task</code></A> </center> <center> [ <A HREF="ch_200_030.htm">Previous</A> | <A HREF="ch_200_050.htm">Next</A> | <A HREF="ch.htm">Contents</A> | <A HREF="help_index.htm">Index</A> | <A HREF="http://www.microapl.co.uk/apl/index.html">APL Home</A> ]</center> <br></td> </tr> </table> <!-- %%COMMON_BODY_TAIL%% --> <p class="copyright">Copyright © 1996-2010 MicroAPL Ltd</p> <!-- %%END%% --> </body> </html>