This project has moved. For the latest updates, please go here.

The library maintains a waiting state even after the call of 'AcquireCompleted'

Aug 13, 2016 at 7:46 AM
Hello everyone.
I'm developing a tool in WPF and I have encountered a problem that occurs when you use a scanner with ADF . I manually set the settings and when calling the ' AcquireCompleted ' I have left the program blocked for hours .
The same code used with a flatbed scanner works great .

How can I solve this problem?
Thank you.
        private void _TwainCompleted(object sender, EventArgs e)
        {
            if (!this._twain32.ShowUI)
            {
                this._twain32.CloseDataSource();
            }
        }

        public void cmd_Scan()
        {
            try
            {
                this._twain32.CloseDataSource();
                this._twain32.ShowUI = sessione.config.isUI;

                if (this._twain32.IsTwain2Supported)
                    this._twain32.IsTwain2Enable = true;

                if (!this._twain32.ShowUI)
                {
                    this._twain32.OpenDataSource();

                    this._twain32.DisableAfterAcquire = false;

                    // Imposto la risoluzione X
                    if ((this._twain32.Capabilities.XResolution.IsSupported() & TwQC.Set) != 0)
                        this._twain32.Capabilities.XResolution.Set(sessione.config.resolution);

                    // Imposto la risoluzione Y
                    if ((this._twain32.Capabilities.YResolution.IsSupported() & TwQC.Set) != 0)
                        this._twain32.Capabilities.YResolution.Set(sessione.config.resolution);

                    // Imposto B/W Gray Color
                    if ((this._twain32.Capabilities.PixelType.IsSupported() & TwQC.Set) != 0)
                        this._twain32.Capabilities.PixelType.Set(sessione.config.pixelType);

                    // Imposto l'autore
                    if ((this._twain32.Capabilities.Author.IsSupported() & TwQC.Set) != 0)
                        this._twain32.Capabilities.Author.Set(AppUtils.getAppName().PadRight(128, '\0'));

                    // Verifico se è supportato il duplex
                    if ((this._twain32.Capabilities.Duplex.IsSupported() & TwQC.GetCurrent) != 0)
                    {
                        TwDX duplexMode = this._twain32.Capabilities.Duplex.GetCurrent();
                        if (duplexMode != TwDX.None)
                        {
                            // Abilito il caricatore.
                            if ((this._twain32.Capabilities.FeederEnabled.IsSupported() & TwQC.Set) != 0)
                            {
                                bool isFeederLoaded = true;
                                this._twain32.Capabilities.FeederEnabled.Set(isFeederLoaded);

                                // Controllo la presenza di documenti nel caricatore. Se non ci sono fogli
                                // disattivo il caricatore.
                                if ((this._twain32.Capabilities.FeederLoaded.IsSupported() & TwQC.GetCurrent) != 0)
                                    isFeederLoaded = this._twain32.Capabilities.FeederLoaded.GetCurrent();

                                this._twain32.Capabilities.FeederEnabled.Set(isFeederLoaded);
                            }

                            //if ((this._twain32.Capabilities.AutoFeed.IsSupported() & TwQC.Set) != 0)
                            //    this._twain32.Capabilities.AutoFeed.Set(true);

                            if ((this._twain32.Capabilities.XferCount.IsSupported() & TwQC.Set) != 0)
                                this._twain32.Capabilities.XferCount.Set(-1);

                            if ((this._twain32.Capabilities.DuplexEnabled.IsSupported() & TwQC.Set) != 0)
                                this._twain32.Capabilities.DuplexEnabled.Set(ckFR);
                        }
                    }
                }

                this._twain32.Acquire();
            }
            catch (Exception ex)
            {
                UC.MBException(ex);
            }
        }
Coordinator
Aug 13, 2016 at 10:22 AM
Hello, alevin.
I don't quite understand the purpose of this code:
            if (!this._twain32.ShowUI)
            {
                this._twain32.CloseDataSource();
            }
                if (!this._twain32.ShowUI)
                {
                    this._twain32.OpenDataSource();

                    this._twain32.DisableAfterAcquire = false;

And this code at all does not make sense, because it is necessary to perform before a Twain32.OpenDSM(). Use TWAIN 2.x
                if (this._twain32.IsTwain2Supported)
                    this._twain32.IsTwain2Enable = true;
Aug 13, 2016 at 12:55 PM
To speed I have not included all the code for my UserControl .
The OpenDSM() is called just created the UserControl .

The OpenDataSource() is called to set the configuration parameters; without the program breaks .

I also need to call the CloseDataSource( ) or I jump after the settings Acquire( ) . For this reason I call her when I finished scanning.
Coordinator
Aug 13, 2016 at 4:01 PM
Hello, alevin.
I will clarify my question.
What do you expect from this line of code.
this._twain32.DisableAfterAcquire = false;
Aug 13, 2016 at 4:19 PM
This line should enable / disable the caller after the acquisition . I tried to remove it , setting it to true to false , but the result does not change .
Coordinator
Aug 13, 2016 at 4:58 PM
Hello, alevin.
I'm afraid you misunderstood the purpose of a Twain32.DisableAfterAcquire property. I suggest you read the TWAIN specification.
Marked as answer by SARAFF on 8/27/2016 at 7:09 AM