TwainAcquireToGdPictureImage inside worker thread

Discussions about TWAIN & WIA scanning in GdPicture.NET using GdPictureImaging.
Post Reply
a235301
Posts: 9
Joined: Sat Apr 07, 2012 4:36 pm

TwainAcquireToGdPictureImage inside worker thread

Post by a235301 » Sat Apr 07, 2012 4:40 pm

I am calling in to TWAIN to scan inside of a worker thread. The hook with my implementation is that the code to do all the TWAIN work is inside a Dll. What happens is that when we call TwainAcquireToGdPictureImage from that dll the code just hangs. If I call into the code to perform the scan outside of the thread the scan works fine. When inside of the thread everything works, opening the source, and even hiding/showing the TWAIN UI works in that if we show the TWAIN UI it shows the UI but then when we click "Scan" in the mftr's TWAIN UI it just hangs. Is there something odd about having the thread inside a dll and calling into TwainAcquireToGdPictureImage?

Thanks!

rgoodson40
Posts: 32
Joined: Sun Jan 30, 2011 8:40 pm

Re: TwainAcquireToGdPictureImage inside worker thread

Post by rgoodson40 » Sat Apr 07, 2012 10:44 pm

Try calling TwainCloseSourceManager from the original thread before the processing begins in the second thread. I was having the exact same problem (clicking Scan in the manufacturer's UI would cause app to freeze) and I believe this is what fixed it. I'll be interested to see if this works for you too.

a235301
Posts: 9
Joined: Sat Apr 07, 2012 4:36 pm

Re: TwainAcquireToGdPictureImage inside worker thread

Post by a235301 » Sun Apr 08, 2012 4:25 pm

I am not opening the source manager at all. I open the source w/o using the source manager. And I am not opening two instances of twain scanning at the same time; only one. I am trying to separate TWAIN from the UI by having the UI in an app and the TWAIN scanning in a dll. The app calls into the TWAIN scanning and I want that in a thread so the app can go and and do it's thing while the scanning is happening. Unfortunately there seems to be some threading problem with the GDPicture component where it locks up upon scanning while it is in a thread. I have seen the example code that GDPicture provides for scanning inside of a thread and I am implementing that arrangement. Albeit in a dll.

a235301
Posts: 9
Joined: Sat Apr 07, 2012 4:36 pm

Re: TwainAcquireToGdPictureImage inside worker thread

Post by a235301 » Sun Apr 08, 2012 10:35 pm

Update: By adding a TwainCloseSource prior to opening the source allows the scan to come off as expected. Odd.

a235301
Posts: 9
Joined: Sat Apr 07, 2012 4:36 pm

Re: TwainAcquireToGdPictureImage inside worker thread

Post by a235301 » Sun Apr 08, 2012 11:29 pm

Well, let's check that....if IntPtr window handle is null for all the Twain calls it works inside the thread otherwise if you actually pass it a real windows handle it locks up. Is there something special that I have to do with the thread in order for this to work?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest