Cancelling pending messages...

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Contact:

Cancelling pending messages...

Post by paulsr » Wed Feb 13, 2013 3:58 am

Greetings:

Maybe there's something I haven't understood about cancelling pending messages when a card stops executing.

If I put...

Code: Select all

on closeCard     
   repeat until the pendingMessages is empty
      cancel item 1 of line 1 of the pendingMessages      
   end repeat      
end closeCard
...shouldn't that stop any handlers that are executing, before the next card executes?

I'm having a problem where I randomly get an execution error on switching cards ... maybe 1 time in 10. The line nbr in the error message is in a handler which should have stopped executing.

In the repeating handler I have something like...

Code: Select all

if "someRoutine" is not in the pendingmessages then 
      send "someRoutine" to me in 10 seconds
end if
Is there something else I need to do?

Many thanks...

--paul

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Cancelling pending messages...

Post by dunbarx » Wed Feb 13, 2013 5:54 am

I use this now and then, and have not played with a set up to test what you are dealing with, but why are you canceling only the first item of each line of the pendingMessages? Each line has four components, an ID, a message, a destination and so forth. Does it help that part of your query if you just cancel the line itself? That is normal practice.

As for the other thing, what is the error message? It seems OK to check if a message is pending before sending it again, though I bet there are simpler ways to do what you need. But what does LC complain about?

Craig Newman

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Cancelling pending messages...

Post by shaosean » Wed Feb 13, 2013 7:05 am

paulsr wrote:...shouldn't that stop any handlers that are executing, before the next card executes?
Nope.. Any handlers that are executing will keep running.. "pending" means they are waiting to run.. If you want to stop currently running handlers you need to "exit to top" but that stops everything (including the repeat loop)..

paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Contact:

Re: Cancelling pending messages...

Post by paulsr » Wed Feb 13, 2013 7:46 am

Thanks for your reply Craig...

You asked why I am cancelling only the first item of each line ... because when I don't fully understand something I hunt around for code and examples.

On this page - http://revolution.byu.edu/time/timeDelay.php - there is an example at the bottom, which shows "cancel item 1 of line 1 of the pendingMessages". Since item 1 contains the ID, I assumed that was what I needed to use in order to cancel something.

And "cancel line 1 of the pendingMessages" gives me an error.

As for the error I'm seeing... "Execution Error. An error occurred on line: 879."

Line 879 is on the card I have just left, and is trying to put something onto screen. So, I think the error is valid and leads me to conclude a handler is still running, when it shouldn't be.

But; now that I've played around some more, I realize I can only make this happen on my iPad, and not on my PC. Maybe this is an iOS problem, and I've posted my msg in the wrong part of the forum.

--paul

paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Contact:

Re: Cancelling pending messages...

Post by paulsr » Wed Feb 13, 2013 7:48 am

shaosean wrote:
paulsr wrote:...shouldn't that stop any handlers that are executing, before the next card executes?
Nope.. Any handlers that are executing will keep running.. "pending" means they are waiting to run.. If you want to stop currently running handlers you need to "exit to top" but that stops everything (including the repeat loop)..
Thanks ... Could you give me an example please ... where do I put the "exit to top"? In the closeCard handler?

--paul

paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Contact:

Re: Cancelling pending messages...

Post by paulsr » Wed Feb 13, 2013 8:02 am

Hmm... I'm not sure "exit to top" is the solution.

What I need is a way to stop any executing handlers when the card stops executing. Is there some way to do this?

Or, should they stop automatically when the card stops?

TIA

--paul

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Cancelling pending messages...

Post by shaosean » Wed Feb 13, 2013 11:49 am

When a handler starts, it only stops when it reaches the 'end' of it, or you force out with the 'exit to top'.. The pendingMessages is to see the handlers that are to be run after the current handler is done.. The cancel command is only used to cancel those pending messages..

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Cancelling pending messages...

Post by Simon » Thu Feb 14, 2013 12:07 am

Hi Paul,
Is there anyway you can re-write this code?

Code: Select all

if "someRoutine" is not in the pendingmessages then 
      send "someRoutine" to me in 10 seconds
end if
As you can see it is in direct conflict to your "cancel pendingMessages" and if triggered will start the message again.
You could probably use just "send "someRoutine" to me in 10 seconds" and get rid of the if-then.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Contact:

Re: Cancelling pending messages...

Post by paulsr » Thu Feb 14, 2013 4:09 am

Hi Simon,

I can't see how your suggestion would help. The check of pendingmessages is just to prevent me restarting the handler more than once. If it's already queued, then I don't need to start it.

What I need to do is stop it when the card ends. Maybe I need to send it a signal, via a custom property or something. Or as shaosean suggests, by using "exit to top" ... but I haven't yet figured where to put this.

Thanks...

--paul

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Cancelling pending messages...

Post by Simon » Thu Feb 14, 2013 4:20 am

Hi Paul,
My point was when you cancel the pendingMessages your if-then restarts it.
As in your if-then will answer true, right after you cancel it and so start it right back up.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Contact:

Re: Cancelling pending messages...

Post by paulsr » Thu Feb 14, 2013 5:05 am

I must need more coffee Simon!

Your solution works fine ... many thanks. But I can't figure why.

--paul

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Cancelling pending messages...

Post by Simon » Thu Feb 14, 2013 6:22 am

Glad it's working for you.
I'm not even sure where your if-then code is. The random occurrence may point to it.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply