Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用c#连接生物识别设备?_C#_Asp.net_Biometrics - Fatal编程技术网

使用c#连接生物识别设备?

使用c#连接生物识别设备?,c#,asp.net,biometrics,C#,Asp.net,Biometrics,我正在尝试在web应用程序中连接生物识别设备。我在windows应用程序中运行良好,但在web应用程序中它会抛出错误 Windows-form.cs: int nPort = Convert.ToInt32(textPort.Text); int nPassword = Convert.ToInt32(textPassword.Text); string strIP = ipAddressContro

我正在尝试在web应用程序中连接生物识别设备。我在windows应用程序中运行良好,但在web应用程序中它会抛出错误

Windows-form.cs:

int nPort = Convert.ToInt32(textPort.Text);
                        int nPassword = Convert.ToInt32(textPassword.Text);
                        string strIP = ipAddressControl1.IPAddress.ToString();
                        bRet = axFP_CLOCK.SetIPAddress(ref strIP, nPort, nPassword);
                        if(!bRet)
                        {
                            return;
                        }
表单设计器:

((System.ComponentModel.ISupportInitialize)(this.axFP_CLOCK)).BeginInit();
       this.axFP_CLOCK.Enabled = true;
            this.axFP_CLOCK.Location = new System.Drawing.Point(476, 382);
            this.axFP_CLOCK.Name = "axFP_CLOCK";
            this.axFP_CLOCK.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axFP_CLOCK.OcxState")));
            this.axFP_CLOCK.Size = new System.Drawing.Size(100, 50);
            this.axFP_CLOCK.TabIndex = 11;
            this.axFP_CLOCK.Visible = false;
    ((System.ComponentModel.ISupportInitialize)(this.axFP_CLOCK)).EndInit();
同样,我尝试在web应用程序中连接,但显示错误: Webform1:

 public AxFP_CLOCKLib.AxFP_CLOCK axFP_CLOCK;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bool bRet;
                string ip= "192.168.1.109";
                int nPort = Convert.ToInt32(5005);
                int nPassword = Convert.ToInt32(0);
                axFP_CLOCK = new AxFP_CLOCKLib.AxFP_CLOCK();
                bRet = axFP_CLOCK.SetIPAddress(ref ip, nPort, nPassword);
                if (!bRet)
                {
                    Response.Write("success");
                }

                else
                {
                    Response.Write("failure");
                }
            }
        }
它抛出错误为

ActiveX控件“87733ee1-d095-442b-a200-6de90c5c8318”不能为空 实例化,因为当前线程不在单线程中 公寓

动态链接库:


有人能帮我纠正这个错误吗?

错误消息表明您正在使用的ActiveX控件需要STA(单线程单元)状态。可以使用方法设置相应线程的单元状态

假设您已经创建了一个
线程
,以如下方式包装ActiveX实例:

var thread = new Thread(() => {
    // other running processes inside thread
    Application.Run();
});
然后在使用
Start()
之前,您应该将该线程的单元状态指定给STA(
ApartmentState.STA
):

此问题背后的原因是大多数.NET后台线程(或工作API)将以多线程单元状态(MTA)的形式创建新线程,而ActiveX控件线程通常以STA模式实例化

相关问题:


错误消息表示您使用的ActiveX控件需要STA(单线程单元)状态。可以使用方法设置相应线程的单元状态

假设您已经创建了一个
线程
,以如下方式包装ActiveX实例:

var thread = new Thread(() => {
    // other running processes inside thread
    Application.Run();
});
然后在使用
Start()
之前,您应该将该线程的单元状态指定给STA(
ApartmentState.STA
):

此问题背后的原因是大多数.NET后台线程(或工作API)将以多线程单元状态(MTA)的形式创建新线程,而ActiveX控件线程通常以STA模式实例化

相关问题:


您应该在
线程中运行方法

像下面这样

var thr = new Thread(new AxFP_CLOCKLib.AxFP_CLOCK().SetIPAddress(ref ip, nPort, nPassword));
    thr.SetApartmentState(ApartmentState.STA);
    thr.Start();
我不是很确定,但是注释你的
页面加载也应该有帮助

  [STAThread]
protected void Page_Load(object sender, EventArgs e)
{
 // Code Goes here
}

您应该在
线程中运行您的方法

像下面这样

var thr = new Thread(new AxFP_CLOCKLib.AxFP_CLOCK().SetIPAddress(ref ip, nPort, nPassword));
    thr.SetApartmentState(ApartmentState.STA);
    thr.Start();
我不是很确定,但是注释你的
页面加载也应该有帮助

  [STAThread]
protected void Page_Load(object sender, EventArgs e)
{
 // Code Goes here
}