Description: | Compels window messages, which are waiting for an event procedure to finish, to execute before the event procedure finishes. For example, if you code an event procedure "A" that takes a long time to execute, and use a Timer control to update the form in the Timer event, the Timer event will wait for the procedure "A" to conclude. If you invoke the ThruEvents method at intervals from the procedure "A", the Timer events work smoothly. Refer to the ThruEvents Example for details. Caution: The ThruEvents method can cause unexpected results because of timing or procedure coding errors. Refer to Unexpected Results when using the ThruEvents Method for more details. Use this method with care. |
Used in controls: | None. |
Used in objects: | Form |
Parameters: | None. |
Return value: | None. |
Example: | See the ThruEvents Example |
Backward compatibility | None. |
Example of the ThruEvents Method
The code below demonstrates code containing a loop that invokes the ThruEvents method every 1000th iteration. This enables the counter to be displayed (every 1000th iteration) and for the event to exit when the cancel button is clicked.
01 RUNNING-FLAG PIC S9(4) GLOBAL VALUE 0. 88 IS-RUNNING VALUE 1.
If the click event is executing, exit program to prevent(restrict) the event nesting
ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 I PIC S9(9) COMP-5. PROCEDURE DIVISION. IF IS-RUNNING THEN EXIT PROGRAM *> Exit to prevent nesting of the event END-IF MOVE 1 TO RUNNING-FLAG. *> Sets the executing flag PERFORM VARYING I FROM 1 BY 1 UNTIL I > 1000000 MOVE I TO "Caption" OF COUNTER *> Display counter IF FUNCTION MOD (I 1000) = 0 THEN INVOKE POW-SELF "ThruEvents" *> Executes any waiting event procedures IF NOT IS-RUNNING THEN *> Exits if the cancel button is clicked EXIT PERFORM END-IF END-IF END-PERFORM MOVE 0 TO RUNNING-FLAG. *> Releases the executing flag
ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. PROCEDURE DIVISION. MOVE 0 TO RUNNING-FLAG. *> Sets the executing flag to 0
ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. LINKAGE SECTION. 01 POW-CANCEL PIC S9(4) COMP-5. PROCEDURE DIVISION USING POW-CANCEL. IF IS-RUNNING THEN MOVE POW-TRUE TO POW-CANCEL END-IF