Last post Mar 13, 2019 02:08 AM by Ackerly Xu
Mar 12, 2019 06:51 AM|paminchever|LINK
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 = "";
strfilename = DateTime.Now.ToString("ddMMyyyyhhmm") + "_" + "CF" + ".pdf";
//var withBlock = AxTwain2;
var withBlock = new AxTwain();
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('No Automatic Document Feeder(Scanner) detected on this Computer. Are you sure you want to continue?');", true);
withBlock.UseADF = true;
withBlock.MultiImage = true;
withBlock.KeepImages = false;
withBlock.ImagesToRead = 0;
withBlock.UseInterface = false;
withBlock.PixelType = TxPixelType.ptRGB;
catch (Exception ex)
Mar 13, 2019 02:08 AM|Ackerly Xu|LINK
The errors shows that your code should run in a single-threaded apartment.
Webform runs in a muti-thread environment by default.
To solve this,one way it to set the AspCompat of page directive , another way is to start a new thread to run your code and set its environment to single-threaded.
For more information , please refer to