LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Destroy User Event - Behaviour vs Documentation

 

During the development of an asynchronous framework which makes extensive use of User Events, I thought I would test the functionality of the 'Destroy User Event' function using the VI attached. With LabVIEW 2018 (SP1) on Windows 10, I see that the event is received by the Event Structure even though the User Event Reference has been destroyed. This would appear to be contrary to the documentation which states that Any Event structures registered for this user event no longer receive the event. 

 

The observed behaviour seems to be both logical and desirable from an encapsulation point of view - If the generator of an event is also the owner of the User Event Reference then the generator can safely destroy the User Event Reference once it has sent it's event "message" and each receiver of the event message only has to destroy their own event registration.

 

My only concern is that this is not what the documentation is alluding to. Am I missing something in my understanding of the documentation or have I made some mistake with my test VI? I would be interested in hearing the opinions of others on this topic.

User Event.png

0 Kudos
Message 1 of 12
(241 Views)

Don't have LabVIEW here, and a bit hard to describe, but I will try.

 

  1. The send and receive for User Events are a bit different than queues. In a queue, everything "lives" on a queue wire reference. If you destroy the queue reference wire than BOTH send and receive will not work. Also you can queue up a bunch of data before the receive is ready and none of the data is lost.
  2. In a user event the send "lives" and the User event wire, and the receive "lives" on the registration event wire. So if you send a User Event before you have registered for it, the data is lost.
  3. In your example you destroy the send, but not the receive. You sent your message before the send refnum was destroyed.

Hopefully this makes sense.

 

mcduff

0 Kudos
Message 2 of 12
(217 Views)

Hi mcduff

 

Thanks for your comment - you description here exactly follows my understanding of what is going on. My question (which I somewhat buried in my post) is:

What does the NI documentation on the Destroy User Event function mean when it says " Any Event structures registered for this user event no longer receive the event"?

 

It doesn't seem to make sense and my fear is that the operation of the function is changed in the future so it does some global destruction of any  'recieve' event associated with the User Event Reference as per the documentation.

 

Cheers

 

John

 

 

0 Kudos
Message 3 of 12
(205 Views)

<duplicate>

0 Kudos
Message 4 of 12
(204 Views)

@mcduff wrote:

Hopefully this makes sense.


Well, it didn't quite make sense, but I think I know what you were trying to say, so I'll "play Professor" and paraphrase (but the ideas and basic credit goes to mcduff!):

  • Queues are created by a single function, "Obtain Queue".  Once the Queue has been "obtained", it is associated with a single "Queue Wire" that is used by both the "writer" (the Enqueue function) and "reader" (the Dequeue function).
  • Once the Queue has been created, both the Enqueuer and Dequeuer can run.  In particular, you can Enqueue multiple items (assuming you haven't specified a finite-length Queue) and they will remain "in the Queue" until the Dequeue function removes them.
  • Destroying the Queue loses any remaining data in the Queue, and cause both Enqueue and Dequeue to generate an Error if run.
  • User Events (in contrast) has two associated References -- the "writer" (Generate User Event) uses the User Event refnum created by Create User Event, while the "reader" (the Event Loop, with Dynamic Event Terminals enabled) uses the Event Registration Refnum created by Register for Events.
  • A consequence of this two-step process is that the Sender and Receiver can have separate "lives". 
    • Any data "sent" by Create User Event before the Event Registration Refnum is generated will be "lost" (as there is no "receiver" yet defined).
    • Conversely, once User Events have been generated in conjunction with an existing Event Registration Refnum, they continue to exist (even if the User Event reference gets destroyed by Destroy User Event) as long as the Event Registration Refnum is still "alive".
    • mcduff didn't say this, but doing "Unregister for Events" will "clean out" any User Events still waiting to be processed.

I've used User Events, but haven't tried doing the "intermediate" creation/destruction of Event components mid-stream, so have not had mcduff's experience (nor knowledge) of the details and timing of the Event process.  In particular, I think his explanation of a separate "writer" (User Events) and "reader" (Event Registration Refnum) data container nicely encapsulates a good way to understand some of the "interesting features" of the Event Loop and User Events.

 

Bob Schor

0 Kudos
Message 5 of 12
(199 Views)

Usually NI does not change functionality.

 

When you destroy the User Event, you are destroying the "mailman" who carries the "letters" to the "mailbox (Register User Events)". You destroyed the mailman, but not the mailbox. The mailbox is still there, it is just that there are no mailmen to deliver letters, so you mailbox will remain empty. (I think this is what NI means, anybody that has a mailbox for these letters can no longer receive them.)

 

You destroy the mailbox after the event structure.

 

mcduff

Message 6 of 12
(198 Views)

@mcduff wrote:

Usually NI does not change functionality.

 

When you destroy the User Event, you are destroying the "mailman" who carries the "letters" to the "mailbox (Register User Events)". You destroyed the mailman, but not the mailbox. The mailbox is still there, it is just that there are no mailmen to deliver letters, so you mailbox will remain empty.


If you've delivered a dozen letters before the HomeOwner looked in the Mailbox, then killed the mailman, wouldn't there still be letters in the Mailbox?  [I should do the Experiment, but I hope the answer is "Yes" ...]

 

Bob Schor

Message 7 of 12
(190 Views)

"No longer receive" isn't the same as "deletes all events received."

 

If the event was received before you killed the user event, it's still there.  Are you seeing any that were sent after you ended the user event still get sent?

Message 8 of 12
(185 Views)

Oops, forgot to push "Post" before I wrote the Test Code (which, fortunately, proved my assertion):

Event Registration.pngEvent Registration Test

I create 12 User Events (0 .. 11), then Register for them (so they should be "lost", then register 12 more (12 .. 23).  In the Event Loop, I save every Event I see (stopping when/if I see "23") and hope I see 12-23 (and I do ...).

 

Bob Schor

0 Kudos
Message 9 of 12
(181 Views)

The documentation for Events tries too hard to simplify things by skipping over the Event-Registration queues that are actually the central important concept.  Personally, I think this makes Events harder to grasp.  You shouldn't worry about the behaviour changing.

Message 10 of 12
(172 Views)