When handling a .NET or ActiveX event, you must register for the event (see steps 1 through 5) and then create a callback VI to handle that event (see steps 6 and 7).
Note National Instruments recommends that you unregister for events when you no longer need to handle them using the Unregister For Events function. If you do not unregister for events, LabVIEW continues to generate and queue the events as long as the VI runs, even if no Event structure is waiting to handle them, which consumes memory and can hang the VI if you enable front panel locking for the events.
Complete the following steps to register and handle .NET and ActiveX events in LabVIEW.
Wire the reference or object to the Event input of the Register Event Callback function.
Click the down arrow next to the Event input on the Register Event Callback function and select an event from the shortcut menu.
(Optional) Wire the data that you want to pass to the callback VI to the User Parameter input. You can wire any LabVIEW data type, including a cluster, to this parameter.
Right-click the VI Ref input and select Create Callback VI from the shortcut menu. LabVIEW creates a VI based on the event you select and the data you wire to the User Parameter. LabVIEW wires the callback VI to the VI Ref input.
Note You can use an existing VI as a callback VI as long as the connector pane of the VI you intend to use matches the connector pane of the event data. The callback VI must be reentrant, and the reference to the callback VI must be strictly typed.
Open the callback VI and edit the block diagram to handle the event. The callback VI contains the following elements:
Event Common Data contains the following elements:
Event Source is a numeric control that specifies the source of the event, such as LabVIEW, .NET, or ActiveX. A value of 1 indicates an ActiveX event. A value of 2 indicates a .NET event.
Event Type specifies which event occurred. This is an enumerated type for user interface events and a 32-bit unsigned integer type for .NET, ActiveX, and other event sources. For .NET and ActiveX events, the event type represents the method code, or ID, for the event registered.
Time Stamp is the time stamp in milliseconds that specifies when the event was generated.
Control Ref is a reference to the .NET or ActiveX object or the Automation Refnum on which the event occurred.
Event Data is a cluster of the parameters specific to the event the callback VI handles. LabVIEW determines the appropriate Event Data when you select an event from the Register Event Callback function. If an event does not have any data associated with it, LabVIEW does not create this control in the callback VI.
Event Data Out is a cluster of the modifiable parameters specific to the event the callback VI handles. This element is available only if the event has output parameters.
(Optional) User Parameter is data that you want to pass to the callback VI when the .NET or ActiveX object generates the event.
Note LabVIEW does not wire the Event Data input to the Event Data Out output automatically. Therefore, if you want to pass any part of the Event Data input through the callback VI, you must wire the Event Data input to the Event Data Out output manually.