Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Accessing a Measurement Studio ActiveX Control and a Native .NET Control in a Multithreaded Program in Visual C#

0 ratings | 0.00 out of 5
Print

Downloads

Filename: multithread.zip
Requirements: View

This program demonstrates how to access a control in a multithreaded program in Visual Studio .NET. Specifically, this program accesses a Measurement Studio Button control and a native .NET Label control in a multithreaded program in Visual C#. When you click the Start button, the CWButton, which is configured as an LED, blinks five times before displaying a success or exception message on the form.

Note that you cannot call a method on a control from a thread other than the thread the control was created in, with the exception of BeginInvoke, EndInvoke, Invoke, InvokeRequired, and CreateGraphics methods. If you need to invoke other functions, then you must do so through the control's or the form's implementation of ISynchronizeInovke (specifically, Invoke or BeginInvoke). This rule applies only to Windows Forms controls, which include ActiveX controls. This rule applies to ActiveX controls because when you use an ActiveX control in a .NET application, you are really using an Interop wrapper control that inherits from AxHost, which inherits from Control. Hence, the wrapper control is a Windows Forms control. When you call methods from other threads with Invoke, this ensures that the method gets called in the thread that created the control, making the call safe. As a result, you can enter a code in the ThreadPool callback method as long as the code does not access Windows Forms controls directly. All the code that accesses any Windows Forms controls directly must be in a callback method that gets invoked by the Invoke method. Refer to the comments in MainForm.cs file.
When using any ActiveX controls in Visual Studio .NET, keep the following differences in mind:
1.) Visual Studio .NET generates a Runtime Callable Wrapper (RCW) around each control, and you must go through the Interop layer to use the controls. As a result, some class names differ from the names in Visual Basic 6.0.
2.) Hosting an ActiveX control in Visual Studio .NET requires unmanaged code permissions.
3.) Hosting an ActiveX control in a Windows Form increases the size of your project files because the entire control is embedded in the form.
For more information about using ActiveX controls in Visual Studio .NET, refer to the Visual Studio .NET help.

Requirements


Filename: multithread.zip

Software Requirements


Application Software: Measurement Studio Visual Basic Support 6.0
Language(s): C#
Additional Software: Visual Studio 7.0

 
0 ratings | 0.00 out of 5
Print

Reader Comments | Submit a comment »

 

Legal
This example program (this "program") was developed by a National Instruments ("NI") Applications Engineer. Although technical support of this program may be made available by National Instruments, this program may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this program with each new revision of related products and drivers. THIS EXAMPLE PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).