The call interface in the Class ActiveX control error resolving the ActiveX control cannot be instantiated because the current thread is not in a single-threaded apartment

Source: Internet
Author: User

The workaround is to define a static ActiveX object in the form class that assigns the ActiveX object on the interface to the newly defined object in the Formload class, which is accessible to the static object.

public static Axclientdriver_ntlib.axclientdriverctrl com = new Axclientdriver_ntlib.axclientdriverctrl ();

private void Form1_Load (object sender, EventArgs e)
{
com = THIS.AXCLIENTDRIVERCTRL1;
IsRunning = true;

This. FormClosing + = form1_formclosing;
Thread t = new thread (startserver);
T.setapartmentstate (ApartmentState.STA);//Key settings
T.start ();

}

public class A

{

public void Getzhiwen ()

{

New Axclientdriver_ntlib.axclientdriverctrl (). Gwq_signfinger (); /* ERROR:

The ActiveX control "f1b35062-91ea-47fd-a71e-872c114220b0" cannot be instantiated because the current thread is not in a single-threaded apartment. System.Threading.ThreadStateException: The ActiveX control "f1b35062-91ea-47fd-a71e-872c114220b0" cannot be instantiated because the current thread is not in a single-threaded apartment. */

Form1.com.GWQ_SignFinger ();

}

}

The call interface in the Class ActiveX control error resolving the ActiveX control cannot be instantiated because the current thread is not in a single-threaded apartment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.