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