Registering and Handling .NET and ActiveX Events

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 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.

  1. Create a new control in a .NET container or an ActiveX container. You also can use the Constructor Node to create a .NET object or use the Automation Refnum to call an ActiveX object from LabVIEW.
  2. Add the Register Event Callback function to the block diagram.

     Add  Find
  3. Wire the reference or object to the Event input of the Register Event Callback function.
  4. Click the down arrow next to the Event input on the Register Event Callback function and select an event from the shortcut menu.
  5. (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.
  6. 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.
  1. Open the callback VI and edit the block diagram to handle the event. The callback VI contains the following elements:
    Note 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.