PxPlus User Forum

Main Board => Discussions => Programming => Topic started by: Thomas Bock on August 29, 2018, 08:29:07 AM

Title: looking for a cancel request
Post by: Thomas Bock on August 29, 2018, 08:29:07 AM
During long processing we display a "Please wait ..." dialog with an optional cancel button. In many cases the working program logic resides much deeper in the call stack than the front end parts. So these programs have no clue of that button and therefore cannot look for a cancel request of the user.
Is there a way to manage a cancel request though (PxPlus V13 and V14)?
Title: Re: looking for a cancel request
Post by: Allen Miglore on August 29, 2018, 08:57:49 AM
You could set/monitor a global variable (%canceled=1) or gbl value (gbl("canceled",err=*next)="1").   Or if multiple processes, you could set/monitor a file or key in a file.
Title: Re: looking for a cancel request
Post by: Mike King on August 29, 2018, 09:23:01 AM
If I understand your question the problem is that when running the application you want to receive some form of signal from the user to stop.   The challenge is doing this without having to "poll" the workstation looking for input.

One thing you could try would be to create a button whose CTL event is -1001 as this emulate a ESCAPE/BREAK being pressed.  You can thus simply create a small window in the center of the screen with this button then have a SETESC in your code trap the event to allow for an orderly exit.  If desired you could also include an animated GIF on the window to show progress to your user.

Personally though I would use the PxPlus progress bar utility and issue a call to it on a regular basis in your logic.  This provides not only a means to do an orderly shutdown but also a visual indication that work is being done.  There are two (2) options with PxPlus progress bars, one that allows you to display the percentage complete and one that just provides a ongoing progress display.  If you know how much of the work has been done I recommend the former option (the percentage complete bar).

BTW: It should be noted that the PxPlus progress bar has built-in logic to only update the screen every few seconds instead of every time it is called.  This helps overall performance which can be impacted by repeatedly screen updates.