我有一个项目,我使用后台工作人员通过 WIA2 从扫描仪异步执行扫描功能。它适用于 WIA。
现在我正在尝试通过使用 TWAIN 扫描来做同样的事情。我可以使用 TWAIN 进行扫描。但是,当我尝试使其在后台工作时,我无法使其正常工作,因为在 TWAIN 中进行扫描的事件有一个 TransferImage 处理程序和一个 ScanningComplete 事件处理程序,它们会在扫描完成时被激发。transferImage 没问题,因为它不会影响我的后台事件。但是我想在scanningComplete事件中访问一个面板,让它.Visible = False
发生的事情的一部分:
Private Sub rBEScan_Click(sender As Object, e As EventArgs) Handles rBEScan.Click
rPScanning.Visible = True
Me.rBEScan.Enabled = False
bGWScan.RunWorkerAsync()
End Sub
Private Sub bGWScan_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bGWScan.DoWork
Dim path As String = ""
Dim correct As Boolean = False
If scanMode = 1 Then
correct = ScannerRead(path, 1)
Else 'TWAIN
images = Nothing
images = New List(Of System.Drawing.Bitmap)
correct = scanTWAIN(gLocalScanner, path)
End If
Dim obj As Object
obj = correct
e.Result = obj
End Sub
Private Sub bGWScan_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) _
Handles bGWScan.RunWorkerCompleted
Dim obj As Object
obj = e.Result
Dim lobj As Boolean
lobj = DirectCast(obj, Boolean)
rPScanning.Visible = False
Me.rBEScannerEskaneatu.Enabled = True
End Sub
Private Shared Function scanTWAIN(ByVal id As String, ByVal path As String) As Boolean ' prompt to scan more pages,
' SCAN TWAIN FUNCTION
AddHandler twain.TransferImage,
Sub(sender As Object, args As TwainDotNet.TransferImageEventArgs)
If (Not (args.Image Is Nothing)) Then
images.Add(args.Image)
End If
End Sub
' Re-enable the form after scanning completes
AddHandler twain.ScanningComplete,
Sub(sender As Object, e As TwainDotNet.ScanningCompleteEventArgs)
'Enabled = True
Dim lobj As String = ""
lobj = FuncionScanner.pdfIrudiraTwain(images, path, gLocalPreguntarRotacion, orritxurisep, orriDok, orriguztiakDok)
PrincipalR.rPScanning.Visible = False
PrincipalR.rBEScan.Enabled = True
End Sub
ScanningFunctionOfTwain With my settings.
End Sub
我的问题是我在扫描图像之前结束了后台工作人员,因为事件是在另一个异步调用的函数中处理和触发的。
关于如何在后台工作人员中结束事件的任何rPScanning.Visible = False
想法rBEScan.Visible = False
。
如果不可能,我应该在 TWAIN 的扫描页面的 eventHandler 中使用另一个后台工作程序。