LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to check if a user event is unregistered before destroying it?

Solved!
Go to solution

I have a number of asynchronously-running VIs each registered to handle a common user event. During shutdown, each of these VIs unregisters itself for that event. Now I want to destroy the event.

 

NI's reference material on user events recommends I wait until all event handlers are unregistered before destroying the event, and I'd like to do it this way, even though waiting might not be necessary in a shutdown situation (suggested in another forum thread).

 

So my question is: how can I check if a user event is completely unregistered before I destroy it?

 

Put another way: is there a way to see how many registered event handlers a given user event has? I'm currently using this VI (see below) to keep track of the number of registered event handlers:

 HandlerCounter.png

(call it with +1 when registering an event handler, -1 when unregistering). It feels like a hack, though, and I'm wondering if there isn't a more proper way of doing this. Ideally some kind of built-in function? This seems like something that LabVIEW would need to keep track of...

 

Thanks in advance,

 

-Kevin

0 Kudos
Message 1 of 5
(2,624 Views)
Solution
Accepted by topic author kshan

Kevin,

 

I've looked through some documentation to verify whether or not a VI like this exists and unforunately the VI library does not contain a way for the user to keep track of the number of registered events. If we had a VI in the library that had the functionality you're looking for it would probably work very similarly to yours under the hood.

 

-Nick-

Nick C | Software Project Manager - LabVIEW Real-Time | National Instruments
0 Kudos
Message 2 of 5
(2,610 Views)

Assuming you register the event in different loops in the same vi (or normal sub-vi's) it's just a case of wiring the error clusters (assuming the unregister doesn't exit until it's correctly unregistered), if it's vi server started vi's you'll need to use semaphores or the like.

 

/Y 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 5
(2,584 Views)

Unfortunately, they are indeed asynchronously started, and a priori I don't even know how many of these event handler subVIs will be running. Some may even be started and stopped multiple times before shutdown.

 

Semaphores are an interesting idea; we'd have to keep one for each subVI and be a little careful about repeated starts, but it would certainly impose a stronger psychological pressure on the subVI developer: "There's a semaphore terminal in the VI type specifier; do the right thing" rather than "Please remember to call this random function before and after you register/unregister your event handler".

 

Thanks, Nick and Yamaeda.

 

-Kevin

 

0 Kudos
Message 4 of 5
(2,570 Views)

We used the semaphore solution, in the form of Rendevouz, in a project i worked in, and i think with some small changes it would work very smooth.

 

The Rendevouz can increase and decrease it's count, meaning you can add or remove listeners as needed. Use a AE for adding, removing and waiting for synch as needed.

 

We started several VI's through vi server and added rendevouz as needed. When killing these VI's we waited for them to synch which often caused problems, especially if one had gotten an error and closed down. 

 

In hindsight it would have been better to simply reduce the count and only wait for synch in the starter VI.

 

/Y 

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 5
(2,562 Views)