Reference Guide > W Routines > WtWorkProc Function
  

WtWorkProc Function
Registers a work procedure for background processing.
Usage
status = WtWorkProc(function, parameters)
Parameters
function:
*'Add' — Registers the specified work procedure.
*'Remove' — Removes the previously registered work procedure.
parameters:
*If 'Add' is specified, also provide these two parameters:
* workproc — A work procedure name (string).
* client_data — (optional) A variable.
*If 'Remove' is specified, also provide the following parameter:
*id — The ID of the work procedure to be removed.
Returned Value
*For 'Add':
*status — The work procedure ID; zero (0) indicates failure.
*For 'Remove':
*status — One (1) indicates success; zero (0) indicates failure.
Keywords
Noparams — If nonzero, calls the work procedure with two parameters: wid (the top-level shell of the application), and client_data.
Once_only — If nonzero, calls the work procedure one time only.
Discussion
WtWorkProc is modeled after functionality available in the X Windows Intrinsics library with XtAddWorkProc and XtRemoveWorkProc. When a work procedure is added, it is executed in its entirety unless a REMOVE call to WtWorkProc is issued before the procedure has been called. If the work procedure does a large amount of processing it could block the widget interface until it has finished running.
A typical implementation using WtWorkProc to perform a large amount of background processing is to break down the processing into a number of discrete steps and execute the steps one at a time in a work procedure which issues another ADD call to WtWorkProc to start the next step. Repeat this process until all the steps have been completed.
For information on the requirements for writing work procedures, see "Adding Work Procedures" in the PV‑WAVE Application Developer’s Guide.
 
note
Rogue Wave has ported a subset of the Widget Toolbox (Wt) functionality available for Motif to Microsoft Windows. Because the Widget Toolbox under Windows is not a complete implementation, we recommend that Windows developers use the PV‑WAVE Widgets (Ww) layer or the VDA Tools when developing GUI applications.
Example
PRO workp1, wid, client_data
   PRINT, 'Executing workp1 Once. Data: ', client_data
END
 
PRO workp2, wid, client_data, unused, workproc_id
   print,'Executing workp2 Repeatedly. Data: ', client_data
END
 
PRO ButtonCB, wid, index
   COMMON wp, wpid2, wp2init
   CASE index of
      1: wpid1 = WtWorkProc('add', 'workp1', 'User Data1', $
         /NoParams, /Once_only)
      2: BEGIN
         wp2init = 1
         wpid2 = WtWorkProc('Add', 'workp2', 'User Data2')
      END
      3: BEGIN
         IF wp2init EQ 1 THEN $
            status = WtWorkProc('Remove', wpid2)
         wp2init = 0
      END
   ENDCASE
END
 
PRO ex1
   COMMON wp, wpid2, wp2init
   topshell = WwInit('app_name', 'appclass_name', workarea)
   labels = ['Start 1', 'Start 2', 'Stop 2']
   bbox = WwButtonBox(workarea, labels, 'ButtonCB')
   wp2init = 0
   status = WwSetValue(topshell, /Display)
   WwLoop
END
Output
Output when 'Start 1' is pressed:
Executing workp1 Once. Data: User Data1
Output when Start 2 is pressed (message repeats until 'Stop 2' button is pressed:
Executing workp2 Repeatedly. Data: Iser Data 2
See Also
For detailed information on GUI development, refer to the PV‑WAVE Application Developer’s Guide.
For more information about how to write an application program based on the PV‑WAVE Widget Toolbox, refer to Using the Widget Toolbox in the PV‑WAVE Application Developer’s Guide.

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.