Cancel a Timer action on Card Change?
Posted: Thu Apr 02, 2020 8:05 pm
I have a timer that re-runs an API call every so many minutes (set by the user), and it runs great as long as I'm on that Card when it runs. But if I've moved to another card, it still tries to run, and fails because it can't find controls referenced in the function I run for the API Call.
I see a few things here and there about cancelling the message called when other actions will create an issue (such as changing cards), but I'm not having success in cancelling the pending message.
Here's what I have (in brief)
Any help is very much appreciated. As always.
I see a few things here and there about cancelling the message called when other actions will create an issue (such as changing cards), but I'm not having success in cancelling the pending message.
Here's what I have (in brief)
Code: Select all
global myPendingMessages
on openCard
checkOnlineMachines
end openCard
on checkOnlineMachines
put field APIToken on card "Settings" into apiToken
if (apiToken = "") or (apiToken is empty) then
...show some warning fields to tell the user to get an API Key
else
... do a bunch of stuff that works when on the card.
else
answer "Something weird happened here!"
end if
end if
put the label of button "UpdateTimeSel" of card "Settings" into updateTimeFrame
send checkOnlineMachines to me in (60 * updateTimeFrame) seconds
put "updated after" && updateTimeFrame after field "Logging"
end checkOnlineMachines
on closeCard
repeat for each line thisMessageID in myPendingMessages
cancel thisMessageID
end repeat
end closeCard