1

可能重复:
单线程单元 - 无法实例化 ActiveX 控件

我正在开发一个Asp.net基于 Web 的模板应用程序Visual Studio 2010。该应用程序的目的是从ID Tech card swipper.

#Default.aspx:
# It contain a Button
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</h2> </asp:Content>

而以下是.cs文件:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AxOposMSR_CCO;

namespace WebApplication1
{   
public partial class _Default : System.Web.UI.Page
{
    AxOPOSMSR axOPOSMSR = new AxOPOSMSR();
    protected void Page_Load(object sender, EventArgs e)
    {

    }


   protected void Button1_Click(object sender, EventArgs e)
     {
        if (axOPOSMSR.Open("IDTECH_SECUREMAG_USBKB") == 0)
        {
            axOPOSMSR.ClaimDevice(100);
            axOPOSMSR.DeviceEnabled = true;
            axOPOSMSR.DataEventEnabled = true;
            Console.WriteLine("cons called");

        }

    }
}

}

当我尝试运行这个项目时,它显示:

ActiveX control 'ccb90122-b81e-11d2-ab74-0040054c3719' cannot be 
instantiated because the current thread is not in a single-threaded apartment.

我用谷歌搜索它,它表明我必须创建一个Active X控制对象并在我的 Web 应用程序中使用该对象。我还关注了一些博客和教程,但没有得到更好的解释。

我是新手C#。我应该怎么做才能解决这个问题?

请在上述应用程序的上下文中向我解释。

4

0 回答 0