LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unregistering for User Events

When unregistering for user events, should I put the unregister after the event structure (like the bottom structure below) or can I put the unregister inside the event structure itself (like the top structure below)? My (limited) testing seems to show that the putting the unregister inside the event structure works like I expect, but I want to make sure I'm not shooting myself in the foot later on. All the examples I've seen show the unregister after, but I'd prefer to have it inside due to the way I've structured my error handling if it isn't going to cause me problems

 

User Events.PNG

0 Kudos
Message 1 of 6
(3,716 Views)

Should not matter either way assuming that event case stops your loop the Event Structure is in.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 6
(3,676 Views)

Most of the time, an event structure is put inside a While loop.  Is that going to be the case here?

 

If the event structure is the only thing in the While loop, I don't think it matters either way.

 

However, if the entire code shown is inside the loop, there may be split seconds where the event isn't registered (since it creates a new registration each loop).  Also, it puts a new registration into memory each loop, and while the second one closes it, the first one leaves it open.

0 Kudos
Message 3 of 6
(3,658 Views)

I think if the event registration is connected to shift register in the while it should not change, even if it is not connected to a shift register is should not change.

 

mcduff

0 Kudos
Message 4 of 6
(3,655 Views)

My preference is on the outside of the loop.  My thoughts are that this makes the flow of operations look like normal G code.  Init, Work, Close.  If you are closing in your 'work' section of your code, then a quick glance at the code might have it look like you aren't performing cleanup properly, and I may need to look through all of you cases to make sure you are.  Functionally I'd say you don't have an issue here either way.

0 Kudos
Message 5 of 6
(3,621 Views)

I have always closed outside the loop (since all the examples show this), however, closing inside of the loop appeals to me for the following reasons:

  1. Block Diagram is smaller
  2. I use the JKI State Machine a lot, and would put the Unregister for Events in the "Data: Cleanup" case along with all of my other references. Then I can look at one case to check if everything is closed.

mcduff

0 Kudos
Message 6 of 6
(3,609 Views)