Aborting a method while it is working

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Aborting a method while it is working

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:59 am

by JADE Kid - Ray Hidayat >> Thu, 11 Jan 2001 6:06:38 GMT

As you can see, I'm on a project which is pretty new to me, so I have many questions.

Right now, I have a little loop that is doing a file transfer. Now sometimes you may want to abort the file transfer. How can I stop the loop from another method, or even better, how can I stop the whole method completely?

--
Ray Hidayat
JADE Kid - 2000
www.jadekids.com

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Aborting a method while it is working

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:59 am

by Craig Shearer >> Thu, 11 Jan 2001 18:56:52 GMT

If you want to stop a method in the middle, then it must be aware that it might have to stop, which means that it needs to be checking for some flag at regular intervals, and if the flag is set, then it exits. There are various means of doing this...

If you want to be able to kill off a method in a similar fashion to using the Jade User Interrupt window, this is not possible from user code.

Craig.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Aborting a method while it is working

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:59 am

by David Mitchell >> Thu, 11 Jan 2001 19:44:17 GMT

Alternatively, if the other method is running in the same thread (eg a button was clicked) then you can raise an exception in that method. If the exception handler is set up correctly, the file transfer loop will be stopped.

bStartTransfer_click
Arms handler
Calls doTransfer

doTransfer()
Transfers the file

bStopTransfer_click()
Runs in same thread as doTransfer so
NormalException.raise_(....);

and the handler just needs to do an abort action or resume next (and clean up the aborted transfer)

This also allows you to put any code to clean up the partial file transfer in an appropriate place.

Don't forget to only handle the exception you need to, and pass back the others.

David

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Aborting a method while it is working

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:59 am

by JADE Kid - Ray Hidayat >> Thu, 11 Jan 2001 23:29:24 GMT

I was thinking about that, but I thought there would be an easier way.

David, firstly, where did your signature go?
Secondly, how do I know if it is on the same thread?

--
Ray Hidayat
JADE Kid - 2000
www.jadekids.com


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 11 guests