06-22-2021 01:29 PM
If I create an event and then register it using a single register event node, I can then wait on that event in two separate loops, both using the same registration refnum, as long as each loop is actively waiting at the event structure, both loops will receive the event (usually).
I did not expect this. I expected only one loop to ever receive the event, whichever was the first to wait for it, similar to how regular queues work. However, most of the time, both loops receive it except in cases where presumably the OS interrupts the execution enough to cause one loop to execute significantly sooner than the other enable it to consume the event while the other misses it
If I delay one of the loops slightly, it will never receive the event as expected as the non-delayed one always consumes the queued event well before the delayed one can.
So at what point is an event actually removed from the event queue and why are multiple event structures able to receive the same event without having to use two separate registration nodes?
Solved! Go to Solution.
06-22-2021 01:56 PM - edited 06-22-2021 01:58 PM
Events should work more like notifiers in the sense that they broadcast the event to all tasks registered for the event. One thing that I have seen in the past is behavior can get a bit strange if you have two event structures registered for the same event in the same block diagram. This is the only time I have seen missed events. When I have used the event structures in separate VIs I have never had a problem nor have I ever missed an event.
It is generally recommended to only have a single event structure in a VI. It can be safe provided they do not register for the same events. However, I error on the safe side and limit a VI to a single event structure.
06-22-2021 01:59 PM
@blackburnite wrote:
If I create an event and then register it using a single register event node, I can then wait on that event in two separate loops, both using the same registration refnum, as long as each loop is actively waiting at the event structure, both loops will receive the event (usually).
You are technically in no-man's land here. DO NOT FORK THE REGISTRATION. If you do, there is no telling what mess will happen, as you have discovered. You should have a registration for each Event Structure. Then each Event Structure will have its own queue.
06-22-2021 02:19 PM
Yes, definitely. I wouldn't do that in any code that was actually getting used. It's more of a curiosity as I didn't actually know what would happen so tried it in a test VI and got an unexpected result.
06-22-2021 02:24 PM
I've never had an issue with multiple event structures registered to the same event as long as they are using their own separate registration and not forking the same registration wire.
As you said, all tasks registered to an event should get it, one-to-many, which does happen. But a single event registration *should* produce a single event queue which when "dequeued" by an event structure should make that event no longer accessible.
But what I'm seeing is that a single event is able to be "dequeued" from a registration queue more than once if multiple event structures, both using the same event registration refnum happen to execute at nearly the same time.
06-22-2021 02:35 PM
Take a peek at this thread and the one linked therein:
https://forums.ni.com/t5/LabVIEW/Sub-VIs-One-Reg-events-to-rule-them-all/m-p/4149499#M1197037
Specifically my post here:
Basically, it seems to be removed when the case finishes executing.
06-22-2021 03:45 PM
That's what I thought initially as well and had tested it by delaying the completion of the first event structure to execute but that did not result in the second event structure also receiving the event.
Retrying that again, I see I had simply put my delay on the wrong loop. It does in fact appear to dequeue upon the completion of the event case. Thanks!
06-22-2021 07:25 PM
Although a bit old, somethings may have changed a bit, the best discussion and examples about Events
https://libraries.io/github/JackDunaway/LabVIEW-User-Events-Tips-Tricks-and-Sundry
mcduff
06-22-2021 08:20 PM
@mcduff wrote:
Although a bit old, somethings may have changed a bit, the best discussion and examples about Events
https://libraries.io/github/JackDunaway/LabVIEW-User-Events-Tips-Tricks-and-Sundry
mcduff
Yeah, NI made some massive updates to event handling the following year (2014). I think most of his tricks still work, but some got fixed.