locked
ERROR: ActiveX control cannot be instantiated because the current thread is not in a single-threaded apartment. RRS feed

  • Question

  • User1046245955 posted

    anyone can help me regarding this error im using c# .net 

    ActiveX control cannot be instantiated because the current thread is not in a single-threaded apartment.

    here's my code for scanning a document with twain dll

    string strMM = "";
    string strDD = "";
    int srlNo = 1;
    string strfilename = "";
    try
    {
    strfilename = DateTime.Now.ToString("ddMMyyyyhhmm") + "_" + "CF" + ".pdf";
    {
    //var withBlock = AxTwain2;

    var withBlock = new AxTwain();

    if (!withBlock.SelectDevice())
    return;

    if (!withBlock.HasADF)
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('No Automatic Document Feeder(Scanner) detected on this Computer. Are you sure you want to continue?');", true);
    return;
    }
    withBlock.UseADF = true;
    withBlock.MultiImage = true;
    withBlock.KeepImages = false;
    withBlock.ImagesToRead = 0;
    withBlock.UseInterface = false;
    withBlock.PixelType = TxPixelType.ptRGB;
    withBlock.ClearPDF();
    withBlock.Acquire();
    withBlock.WritePDF(strfilename);
    System.Diagnostics.Process.Start(strfilename);
    }
    }
    catch (Exception ex)
    {
     Interaction.MsgBox(ex.Message);
    }

    Tuesday, March 12, 2019 6:51 AM

All replies