This project is read-only.

How to avoid GUI freezing?

Feb 24, 2012 at 12:03 PM

Hi everybody,

I'm using openTwain for a prototype project I am coding for myself.

The main idea is to apply some modification to guiHarness.vbproj in a way that it will be possible to start and stop scanning by pressing 2 different button.

I'm using kodak kds_i30_i40 twain driver in simulation mode to test my application and the latest twain_32.dll.

Please note I can acquire succesfully and operate with the twain source without problem meaning that  when I use the original guiHarness.vbproj I can select the source, I can create profiles and I can acquire and see at the end the saved images in  the output directory.

1) Start button

I've mapped a start button with the Acquire function, easy. The problem here is that during acquisition (with or without scan GUI) the main form freeze.

First attempt: I've created a delegate function to call the acquire but i god three error trying accessing the tvMain.

Second attempt: I've decided to open a new form (same level as Manager vb) and it freeze too. So again I've tried to create a delegate function and again a run in thread exemption.

Third attempt: I create a new form as a child of openTwain to avoid all the thread issues. The form is launched within the execution of the acquire function just before the StartAquire function. 

Also in this case the GUI is freezing :-( 

2) Stop Button

The stop button is placed on the new Form which show the captured image but I cannot click on it till the scan end.

It' ll be nice to stop the acquisition during scanning from the GUI . e.g.: an image is wrong due to a wrong orientation paper, pause a scanning job etc.

Thanks in advance for all your suggestion.





Mar 2, 2012 at 7:56 AM

your first question is, more or less, a threading question.  the gui sample is running the twain integration on your Ui thread.  If you want to your gui to be responsive during the acquire then you need another thread.  If you look at the cmd sample you'll see some of what you're looking for as the cmd sample specifically uses another thread.

then for the stop,.. if you want to cancel during 1 image you may have to be violent - killing the thread that run the acquire may to what you want for some drivers but I would hesitate to believe that you can get all drivers be behave.  

If you want to cancel in-between one image and another then you'll, more or less, need to get into cTwain.vb.  In both TransferPicturesAsFile & TransferPicturesAsNative there is a loop that checks for PendingXfers = True.  Add some code so that that loop checks for both PendingXfers = True AndAlso SomeOtherFunction_TheUserCancelledTheTranser = False.

you might find that is useful for help with cancelling an acquire.



Mar 5, 2012 at 10:46 AM

I've done it, thanks for your feedback.

Meanwhile I was waiting your suggestions I've investigated more deeply the code and solved the issue the same way you suggested.

I've used a background worker which run a different thread not freezing the GUI and then I've implemented the control to stop scanning in the TrabsferPicturesAsXXXX

Many thanks,