Cancelling scan causes application freeze

Questions, comments and suggestions concerning VintaSoft Twain .NET SDK.

Moderator: Alex

Post Reply
DanielLW
Posts: 22
Joined: Tue Sep 01, 2015 2:42 pm

Cancelling scan causes application freeze

Post by DanielLW »

Hello VS-Team,

first thread was deleted in error, so another one.
Problem: When cancelling the scan process in the scanner driver's progress dialog, the application does not respond anymore. It seems that the method-call of "AcquireModal" does not return in this case (the switch-line is never reached). Here is the code:

Code: Select all

            bool bFinished = false;
            Device deScan = null;
            DeviceManager dmScan = null;
            AcquireModalState amsScan;

            try
            {
                TwainEnvironment.EnableDebugging(@"c:\vstwain.log");

                dmScan = new DeviceManager(this);
                dmScan.Open();
                dmScan.ShowDefaultDeviceSelectionDialog();

                deScan = dmScan.DefaultDevice;
                deScan.Open();

                deScan.ShowUI = false;
                deScan.ModalUI = true;
                deScan.ShowIndicators = true;
                deScan.DisableAfterAcquire = true;
                deScan.TransferMode = Vintasoft.Twain.TransferMode.Native;
                deScan.DocumentFeeder.Enabled = true;
                deScan.PixelType = Vintasoft.Twain.PixelType.BW;
                deScan.Resolution = new Resolution(150, 150);

                do
                {
                    amsScan = deScan.AcquireModal();

                    switch (amsScan)
                    {
                        case AcquireModalState.ImageAcquired:
                            deScan.AcquiredImage.Dispose();
                            break;
                        case AcquireModalState.ScanCanceled:
                        case AcquireModalState.ScanCompleted:
                        case AcquireModalState.ScanFailed:
                        case AcquireModalState.UserInterfaceClosed:
                        case AcquireModalState.None:
                            bFinished = true;
                            break;
                    }
                }
                while (!bFinished);
                
                MessageBox.Show("Finished");
            }
            catch (Exception eError)
            {
                MessageBox.Show(eError.Message);
            }
            finally
            {
                if (deScan != null && deScan.State != DeviceState.Closed)
                {
                    deScan.Close();
                    deScan.Dispose();
                }

                if (dmScan != null && dmScan.State != DeviceManagerState.Closed)
                {
                    dmScan.Close();
                    dmScan.Dispose();
                }
            }
I've also tried this using the async-scanning method, but the behaviour is identical (none of the event-procedures are called). The application freezes, and the main window is disabled.

The twain debug log:

Code: Select all

24.11.2015 16:18:28 29,532,160   Debugging enabled [9.1.5.1]
24.11.2015 16:18:28 29,585,408   Device manager is opening PathToDSM=C:\Windows\TWAIN_32.DLL
24.11.2015 16:18:28 29,593,600     DeviceManagerStateChanged Closed => Loaded
24.11.2015 16:18:28 29,593,600     DeviceManagerStateChanged Loaded => Opened
24.11.2015 16:18:28 29,593,600   Device manager is opened
24.11.2015 16:18:29 29,798,400     Device is opening
24.11.2015 16:18:30 31,526,912       DeviceStateChanged Closed => Opened
24.11.2015 16:18:30 31,535,104     Device is opened: Id(52), Version(1, 0, 13, 1, December, 2001), Protocol(1.9), Groups(3), Manuf(Hewlett-Packard), ProdFamily(All-in-One), ProdName(hp scanjet 5590 TWAIN)
24.11.2015 16:18:30 31,653,888       Getting value of capability Name=SupportedCaps Method=Get
24.11.2015 16:18:30 31,682,560         UsageMode=Get
24.11.2015 16:18:30 31,682,560         ContainerType=Array
24.11.2015 16:18:30 31,711,232         ValueType=UInt16
24.11.2015 16:18:30 31,715,328       Capability value is received
24.11.2015 16:18:30 31,752,192       Getting value of capability Name=FeederEnabled Method=GetCurrent
24.11.2015 16:18:30 31,752,192         UsageMode=Get, Set, GetDefault, Reset
24.11.2015 16:18:30 31,752,192         ContainerType=OneValue
24.11.2015 16:18:30 31,752,192         ValueType=Bool CurrentValue=True
24.11.2015 16:18:30 31,760,384       Capability value is received
24.11.2015 16:18:30 31,772,672       Setting value of capability Name=FeederEnabled ValueType=System.Boolean Value=True
24.11.2015 16:18:30 31,797,248         Result: Success
24.11.2015 16:18:30 31,797,248       Capability value is set
24.11.2015 16:18:30 31,817,728       Setting value of capability Name=IPixelType ValueType=System.UInt16 Value=0
24.11.2015 16:18:30 31,817,728         Result: Success
24.11.2015 16:18:30 31,817,728       Capability value is set
24.11.2015 16:18:30 31,825,920       Setting value of capability Name=IXResolution ValueType=System.Single Value=150
24.11.2015 16:18:30 31,838,208         Result: Success
24.11.2015 16:18:30 31,838,208       Capability value is set
24.11.2015 16:18:30 31,838,208       Setting value of capability Name=IYResolution ValueType=System.Single Value=150
24.11.2015 16:18:30 31,846,400         Result: Success
24.11.2015 16:18:30 31,846,400       Capability value is set
24.11.2015 16:18:30 31,907,840       Getting value of capability Name=Indicators Method=GetCurrent
24.11.2015 16:18:30 31,916,032         UsageMode=Get, Set, GetDefault, Reset
24.11.2015 16:18:30 31,916,032         ContainerType=OneValue
24.11.2015 16:18:30 31,916,032         ValueType=Bool CurrentValue=True
24.11.2015 16:18:30 31,924,224       Capability value is received
24.11.2015 16:18:30 31,924,224       Getting value of capability Name=IXferMech Method=GetCurrent
24.11.2015 16:18:30 31,924,224         UsageMode=Get, Set, GetDefault, Reset
24.11.2015 16:18:30 31,924,224         ContainerType=OneValue
24.11.2015 16:18:30 31,924,224         ValueType=UInt16 CurrentValue=0
24.11.2015 16:18:30 31,932,416       Capability value is received
24.11.2015 16:18:30 31,940,608       Device is enabling ShowUI=False ModalUI=True
24.11.2015 16:19:05 32,030,720       DeviceStateChanged Opened => Enabled
24.11.2015 16:19:05 35,921,920       Received request to close the device
Scanner is a HP scanjet 5590. When scanning through another twain application (like twacker from twain.org), the problem does not occur.

What can possible cause this behaviour?

Thank you for your support.

Best regards,
Daniel
Alex
Site Admin
Posts: 2300
Joined: Thu Jul 10, 2008 2:21 pm

Re: Cancelling scan causes application freeze

Post by Alex »

Hello Daniel,

Please create new advanced log-file and send it to me, we need advanced log because standard log-file does not have enough information for understanding the problem.

Here are steps which you should do if you want to generate an extended log-file of scanner's work:
  • Enable logging (add the lines below to code of your application):

    Code: Select all

    TwainEnvironment.EnableDebugging("d:\vstwain.log")
    TwainEnvironment.DebugLevel = DebugLevel.Debug
  • Run your application.
  • Send us a log-file.
Best regards, Alexander
DanielLW
Posts: 22
Joined: Tue Sep 01, 2015 2:42 pm

Re: Cancelling scan causes application freeze

Post by DanielLW »

I've sent the advanced log to your support address.
Alex
Site Admin
Posts: 2300
Joined: Thu Jul 10, 2008 2:21 pm

Re: Cancelling scan causes application freeze

Post by Alex »

Hello Daniel,

In version 10.0 we have significantly improved the algorithm that cancels image scanning. I think now SDK should work correctly with your scanner. Please check this and let me know results if possible.

Best regards, Alexander
DanielLW
Posts: 22
Joined: Tue Sep 01, 2015 2:42 pm

Re: Cancelling scan causes application freeze

Post by DanielLW »

Hello Alex,

the problem is solved, thank you!
Post Reply