Page 1 of 1

Message queue (SOLVED)

Posted: Thu Feb 04, 2016 8:17 am
by MaxV
Hi,
I really don't know what is the best practice for creating a message queue.
I have a button that user can click any number of times: every time he clicks a process starts, but the new process can't start untill the old one finished.
The process duration time may change, so I can't use send to me in xxx sec.
I need to create a message queue, so every time the user clicks, he just add a process start request to a list.
I'm very scared of using something like repeat forever cicles to check the list.
(I'll need at least 16 of these buttons)

Re: Message queue

Posted: Thu Feb 04, 2016 8:43 am
by SparkOut
On clicking a button, add the message to a list, eg custom property or field ( your queue) and send a message in 0 milliseconds to start the queue handler and set a flag to show it is running, or don't send the message if already running.
In the queue handler, take the first message in the list, remove it and unset the running flag if the list is now empty. Handle the queued item. On ending that handler check if the handler running flag is set and if so, call it again.
Best practice? Not sure but it seems doable

Re: Message queue

Posted: Thu Feb 04, 2016 1:16 pm
by MaxV
I tried it, but I get weird results.
Does anyone have some working example?

Re: Message queue (SOLVED)

Posted: Thu Feb 04, 2016 4:37 pm
by MaxV
I solved this way:
########CODE#######
on mymess var1,var2
if the occupato of me then
send ("mymess " & var1 & comma & var2) to me in 0.1 sec
exit mymess
end if
set the occupato of me to true
#...the remaining code
#...
set the occupato of me to false
end mymess
#####END OF CODE#####

My mistake was to use the custom property also for other puporses, messing all... :oops: