Sends the cancel current transfer command to the device (transfer will not be canceled right after execution of this method).
Visual Basic |
---|
Public Sub Device_CancelImageTransfer() |
Private VSTwain1 As New VintaSoftTwain() Private _isScanFinished As Boolean Private _isScanCanceled As Boolean ''' <summary> ''' This method scans one image and cancels image scan. ''' </summary> Private Sub ScanOneImageAndCancelScan() _isScanFinished = False _isScanCanceled = False VSTwain1.DeviceManager_IsTwain2Compatible = True ' open the device manager If Not VSTwain1.DeviceManager_Open() Then Console.WriteLine(VSTwain1.errorString) Exit Sub End If ' get the device index Dim deviceName As String = "KODAK Scanner: i5000" Dim deviceIndex As Integer = VSTwain1.DeviceManager_FindDevice(deviceName) If deviceIndex = -1 Then Throw New ApplicationException(String.Format("Device '{0}' is not found.", deviceName)) End If ' select the device by index VSTwain1.DeviceManager_SelectedDeviceIndex = deviceIndex ' disable device UI VSTwain1.Device_ShowUI = False ' specify that device must be closed after scan VSTwain1.Device_DisableAfterAcquire = True ' open the device If Not VSTwain1.Device_Open Then Console.WriteLine(VSTwain1.errorString) Exit Sub End If ' specify that 2 images must be acquired from scanner VSTwain1.Device_XferCount = 2 ' subscribe to the device events AddHandler VSTwain1.DeviceImageAcquired, AddressOf VSTwain1_ImageAcquired AddHandler VSTwain1.DeviceScanCompleted, AddressOf VSTwain1_ScanCompleted AddHandler VSTwain1.DeviceScanFailed, AddressOf VSTwain1_ScanFailed AddHandler VSTwain1.DeviceScanCanceled, AddressOf VSTwain1_ScanCanceled ' run asynchronous image acqusition VSTwain1.Device_AcquireImage() ' wait while feeder will be stopped While Not _isScanFinished Application.DoEvents() End While ' unsubscribe from device events RemoveHandler VSTwain1.DeviceImageAcquired, AddressOf VSTwain1_ImageAcquired RemoveHandler VSTwain1.DeviceScanCompleted, AddressOf VSTwain1_ScanCompleted RemoveHandler VSTwain1.DeviceScanFailed, AddressOf VSTwain1_ScanFailed RemoveHandler VSTwain1.DeviceScanCanceled, AddressOf VSTwain1_ScanCanceled ' close the device VSTwain1.Device_Close() If Not _isScanCanceled Then Throw New ApplicationException("Scan is NOT canceled.") End If End Sub Private Sub VSTwain1_ImageAcquired() Console.WriteLine("Image is acquired.") ' cancel image scan VSTwain1.Device_CancelImageTransfer() End Sub Private Sub VSTwain1_ScanCompleted() Console.WriteLine("Scan is completed.") _isScanFinished = True End Sub Private Sub VSTwain1_ScanFailed(errorString As String) Console.WriteLine(String.Format("Scan is failed: {0}.", errorString)) _isScanFinished = True End Sub Private Sub VSTwain1_ScanCanceled() _isScanCanceled = True Console.WriteLine("Scan is canceled.") _isScanFinished = True End Sub