I usually disable buttons and prevent the user from doing anything until whatever is currently happening, is done. I want to provide an Abort button so the user can escape/cancel an operation if desired. Let's say I'm in a sub or function, running loops, doing math, saving data to files or whatever. If the Abort button unceremoniously dumps me back to the callback function, how do I clean up the mess from whence I came? Finish storing data, close files, etc. Is there some accepted way to handle this?
Announcement
Collapse
No announcement yet.
Allowing user to abort a function
Collapse
X
-
I normally use a global variable and check it at various points in the code. When its 'set', I do whatever 'cleanup' is necessary and then exit out of the current process.
If you don't like globals, you can assign a long value to your form or to a control (like the 'abort button') and accomplish the same thing.
For what its worth, I would never use a strategy that simply bailed out of the current process. I always trap the abort flag myself and deal with it in my code. If the 'cleanup' process will be lengthy, you can popup a warning box, display a statusbar message, or do something else to indicate that the abort has been acknowledged and is being acted upon.Software makes Hardware Happen
-
Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
Minor Update
If you use Michael's GUI + Worker Thread + Abort Demo 11-24-07 with PB 9.0
Note that: THREAD CREATE no longer requires, or accepts, the SUSPEND argument.
Replace:
Code:THREAD CREATE WorkerThreadFunction (CBHNDL) SUSPEND TO hThread
Code:THREAD CREATE WorkerThreadFunction (CBHNDL) TO hThread
Comment
-
Thank you for your kind words. Yes I did think about a book once for about 20 minutes, which is all it took to figure out I could not make any money on one.
>Note that: THREAD CREATE no longer requires, or accepts, the SUSPEND argument
Huh?
My Win 9.0 help shows syntax:
Syntax
THREAD CREATE FuncName (param) [StackSize,] [SUSPEND] TO hThread
Code:THREAD CREATE FuncName (param) , SUSPEND TO hThread
Of course that would make the correct syntax diagram
Code:THREAD CREATE FuncName (param) [StackSize] [,SUSPEND] TO hThread
Last edited by Michael Mattias; 20 Oct 2008, 01:10 PM.Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
on this one I have to stick with MCM
from the docs
Thread Create Syntax
THREAD CREATE FuncName (param) [StackSize,] [SUSPEND] TO hThread
THREAD SUSPEND hThread TO lResult&Engineer's Motto: If it aint broke take it apart and fix it
"If at 1st you don't succeed... call it version 1.0"
"Half of Programming is coding"....."The other 90% is DEBUGGING"
"Document my code????" .... "WHYYY??? do you think they call it CODE? "
Comment
-
Well, I tried eight different syntax variations with Win/9 this AM and nothing would compile, so I sent in a bug report.
Let me see if I can code up a version-testing way to do this. THis is a nice demo and I'd hate to see it obsoleted.
MCMMichael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
Comment