07-01-2009 08:42 AM
Is it possible to have an event which interrupts another event handle rutine? I mean, I have one event handle structure with several events (cases). One of this event takes place, and the structure starts to run its rutine. Meanwhile, that rutine is running, other event takes place. Is there any way to stop the first event rutine to execute the second one?
Thanks!
Solved! Go to Solution.
07-01-2009 08:52 AM
No. Not really.
Event structures should not have any code embedded in them that may take a long time to run and block other events. If you do have such a routine, you should move that to another while loop using a producer/consumer architecture with queues. The event structure would just load a command into a queue that the other while loop would dequeue and start working on. The event structure's loop will become quickly available to process other events.
If the second event is one that is intended to interrupt the first routine, then you just need to have the right communication architecture to send to the other loop. This could be another queue command, perhaps a notifier or occurence. A local variable or functional global variable.
Remember that you can't stop any structure in the middle of its process. A while loop can be stopped, but all the code in the while loop must execute before that iteration of the loop is stopped.
07-26-2011 06:21 AM
Hmmm.. I too would like to do this and don't have time to learn the producer/consumer architecture today to get this working. I need a quick and dirty solution.
Surely there must be a way to break out of an event structure if the user hits an emergency stop button?
I guess I could just continuously poll the button within the structure and if it is pressed, use that to set all outputs to zero.
Thoughts?
Dave
07-26-2011 08:36 AM
It sounds like a hack that is going to cost your more time and give you trouble and headaches down the road, then the time it will take to figure out a producer/consumer architecture if you start learning and working with it today.