Developer Center Resources

cancel
Showing results for 
Search instead for 
Did you mean: 

Embedding/Hosting .NET UI Controls on a LabVIEW Front Panel

» Calling External Code From LabVIEW » .NET Assemblies » Embedding UI Controls

LabVIEW allows you to embed a .NET Control on a VIs front panel that users can interact with during runtime. The .NET Container (Controls Palette » .NET & ActiveX » .NET Container) allows you to specify an assembly and the control within the assembly that you want to embed.

The .NET Container has a Block Diagram node that is a reference to the control, and can be wired to .NET Property Nodes and .NET Invoke Nodes to access properties and methods of the control.

For example, to create a System.Windows.Forms.TextBox .NET Control:

  1. Switch to the Front Panel
  2. Drop in a .NET Container
    (Controls Palette » .NET & ActiveX » .NET Container)
  3. Right click on the .NET Container and select Insert .NET Control…
  4. This brings up the Select .NET Control dialog
  5. Pick System.Windows.Forms from the Assembly dropdow
  6. From the list of Controls, select TextBox
    030CreateTextBox.png

Caveat: Multiple Threads and UI Updates

One of the inherent benefits of LabVIEW is that it will create automatically create multiple threads for operations that are not dependent on each other. For instance, two while loops will automatically run on separate threads (unless one while loop has an input that is waiting on an output from the other while loop).

However, this can cause issues when trying to update a .NET Control from LabVIEW. If the code that is updating a .NET Control isn’t running on the same thread that created the control (the UI thread), then .NET can throw an exception. This is done as a safety mechanism to prevent multiple threads from updating the UI in an unsafe manner.

The workaround for this is to force the UI update to run on the UI thread. To do this, you can use the Invoke method of the UI object and specify a function (using a delegate) that will update the UI.

An example of this is shown at:
http://msdn.microsoft.com/en-us/library/ms171728%28VS.80%29.aspx

MSDN: How to Make Thread-Safe Calls to Windows Forms Controls

Attached is an example application showing how this from LabVIEW:

Updating dotNET UI Control from Multiple Threads

References & Examples

The following examples install with LabVIEW:
Calculator VI: labview\examples\comm\dotnet\Calculator.llb
SimpleTaskMonitor VI: labview\examples\comm\dotnet\SimpleTaskMonitor.llb

Community Example: Calling .NET Assemblies from LabVIEW

LabVIEW Help: Creating .NET Controls in a .NET Container

Jervin Justin
NI TestStand Product Manager
Contributors