Announcement

Collapse
No announcement yet.

Allowing user to abort a function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Allowing user to abort a function

    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?

  • #2
    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

    Comment


    • #3
      GUI + Worker Thread + Abort Demo 11-24-07

      HEAVILY commented.


      MCM
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Thanks!

        Michael- have you ever considered writing a book? You seem to have an excellent and detailed example at hand for just about everything!

        CH

        Comment


        • #5
          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
          With:
          Code:
          THREAD CREATE      WorkerThreadFunction (CBHNDL) TO hThread

          Comment


          • #6
            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
            Maybe it needs the 'empty' comma to 'hold a place' for stack size eg
            Code:
            THREAD CREATE FuncName (param) , SUSPEND TO hThread
            Otherwise I don't know how it could tell if 'SUSPEND' is a keyword option or an invalid stack size. (Unless it assumes that 'SUSPEND' - if used - will always immediately precede the 'TO' keyword).

            Of course that would make the correct syntax diagram
            Code:
             THREAD CREATE FuncName (param) [StackSize] [,SUSPEND] TO hThread
            MCM
            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


            • #7
              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 Syntax
              THREAD SUSPEND hThread TO lResult&
              So I do not see where suspend is no longer supported???
              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


              • #8
                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.


                MCM
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment

                Working...
                X