Multi-threaded scanning issues

Discussions about TWAIN & WIA scanning in GdPicture.NET using GdPictureImaging.
Post Reply
rgoodson40
Posts: 32
Joined: Sun Jan 30, 2011 8:40 pm

Multi-threaded scanning issues

Post by rgoodson40 » Wed Mar 28, 2012 11:35 pm

Hello,

I pretty much have GdPicture built into my entire application now except for one hickup, multi-threaded scanning. I have been working on it for a couple of days now but I just can't seem to get it to work. I have two scanners that I am working with. One is the Epson GT-S80 and the other is the Xerox Documate 510. Each scanner is working differently so I will try to explain. Hopefully there is an easy solution. By the way, I am using a Windows 7 64-bit computer and Visual Basic 2008 targeting the .NET 3.5 Framework and the X86 Platform.

Epson GT-S80 Twain driver - I have finally been able to get it to work on a separate thread. The problem is if I refer to the TWAIN source from anywhere in the original thread (such as by calling TwainSelectSource), the source manager gets opened and so for some reason the scanner will not function in the second thread. I was able to get it to work by calling the "TwainCloseSourceManager" method from the original thread before moving into the second thread.

Xerox Documate 510 Twain driver - The method TwainOpenSource does not open this scanner for some reason. It works fine in a single thread.

Epson GT-S80 WIA and Xerox Documate 510 WIA drivers - The scanners open when the TwainOpenSource method is called, however the code freezes on the line TwainAcquireToGdPictureImage and never exits. They also work fine in a single thread.

Here is my code:

Code: Select all

    	Private oGdPictureImaging As New GdPictureImaging
    	Private SelectedScanner As String

	
    	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

                    If oGdPictureImaging.TwainSelectSource(IntPtr.Zero) = True Then
                        SelectedScanner = oGdPictureImaging.TwainGetDefaultSourceName(IntPtr.Zero)

                        MsgBox(oGdPictureImaging.TwainGetState.ToString)

                        oGdPictureImaging.TwainCloseSourceManager(IntPtr.Zero)

                        MsgBox(oGdPictureImaging.TwainGetState.ToString)

                        Dim oThread As New Threading.Thread(AddressOf DoScan)
                        oThread.Start()
                     End If

                End Sub

	Private Sub DoScan()

                     Dim GdPictureImageID As Integer

                     Try
                           If oGdPictureImaging.TwainOpenSource(IntPtr.Zero, SelectedScanner) Then

                               oGdPictureImaging.TwainSetIndicators(True)

                               'Scan the page
                               GdPictureImageID = oGdPictureImaging.TwainAcquireToGdPictureImage(IntPtr.Zero)

                           End If

                      Catch
                      End Try

                      oGdPictureImaging.TwainCloseSource()

               End Sub

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Multi-threaded scanning issues

Post by Loïc » Thu Mar 29, 2012 11:08 am

Hello,

I've updated the asynchronous TWAIN scanning sample using better practices.
You can find it here: viewtopic.php?t=2861

Could you try it with your scanners ? If they work / do not work you can update the thread.

Kind regards,

Loïc

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

Re: Multi-threaded scanning issues

Post by rgoodson40 » Fri Mar 30, 2012 7:18 pm

Thank you. This works, however I had to make a couple of changes.

1) I had to add the call to m_GdPictureImaging.TwainCloseSourceManager(IntPtr.Zero) directly after the call to m_GdPictureImaging.TwainSelectSource(IntPtr.Zero) in the Button1_Click routine.

2) I had to change all references to "m_hwnd" to "IntPtr.Zero".

Before I did these two things, the code would just stall on the line m_GdPictureImaging.TwainAcquireToGdPictureImage.

Now I have 3 of the 4 drivers working correctly. The only outstanding issue is with the Xerox Documate 510 Twain driver, which still will not open within the second thread. I re-installed the driver but I am still getting the same issue.

I think it is probably an issue with the scanner, so I am going to do a workaround. I am going to give my user the ability to turn off multi-threaded scanning just in case their scanner has the same issues as this one. Since I have 3 of the 4 working, I am going to hope that this solution will work with the majority of scanners out there.

If you know of a reason why I should not implement the two changes I mentioned above, please let me know.

Thanks,
Reagan

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

Re: Multi-threaded scanning issues

Post by rgoodson40 » Fri Mar 30, 2012 7:29 pm

Ok, so I guess I jumped the gun a little bit when I posted my last response. It turns out that the reason the WIA drivers were stalling out on the line MyGdPictureImaging.TwainAcquireToGdPictureImage(IntPtr.Zero) is because I didn't have the line MyGdPictureImaging.TwainSetHideUI(True) in there. They work fine when I include that line, so therefore the issue is that they were attempting to the display the UI but couldn't for some reason.

The problem is that I need to display the UI. It works fine with the TWAIN driver, but not for the WIA drivers. Do you know how I can display the WIA user interface within the second thread? I do not want to have to control the scanner's settings myself because I don't want to have to restrict the user's options.

Thanks,
Reagan

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Multi-threaded scanning issues

Post by Loïc » Sun Apr 01, 2012 12:15 pm

Hello,

First you should not use the WIA driver. Also I do not understand why you need to modify my snippet. I can not validate your 1 & 2 modifications.

What I can suggest is to use my snippet in a standalone app with latest TWAIN DSM & no WIA driver. If you find a scanner that do not work, please follow this ticket to provide us required information: viewtopic.php?t=1486

So far I've not found any modern scanner which do not works in this configuration.

Kind regards,

Loïc

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest