CancelTransfer() Method (Device)
In This Topic
Sends the cancel current transfer command to the device (transfer will not be canceled right after execution of this method).
Syntax
'Declaration
Public Sub CancelTransfer()
public void CancelTransfer()
public: void CancelTransfer()
public:
void CancelTransfer()
Exceptions
Exception | Description |
DebuggerException | Thrown if the .NET debugger is used and the function evaluation requires all threads to run. |
Remarks
Important: Transfer will not be canceled right after execution of this method, transfer will be canceled when the ScanCanceled event occurs or the AcquireModal method returns AcquireModalState.None.
Example
This C#/VB.NET code shows how to cancel current asynchronous image transfer.
Class SyncScan_Cancel
''' <summary>
''' This method scans one image and cancels image scan.
''' </summary>
Public Shared Sub ScanOneImageAndCancelScan()
Dim isScanCanceled As Boolean = False
' create the device manager
Using deviceManager As New Vintasoft.Twain.DeviceManager()
deviceManager.IsTwain2Compatible = True
' open the device manager
deviceManager.Open()
' get the device
Dim deviceName As String = "KODAK Scanner: i5000"
Dim device As Vintasoft.Twain.Device = deviceManager.Devices.Find(deviceName)
If device Is Nothing Then
Throw New ApplicationException(String.Format("Device '{0}' is not found.", deviceName))
End If
' disable device UI
device.ShowUI = False
' specify that device must be closed after scan
device.DisableAfterAcquire = True
' open the device
device.Open()
' specify that 2 images must be acquired from scanner
device.XferCount = 2
' run asynchronous image acquisition
Dim acquireModalState1 As Vintasoft.Twain.AcquireModalState = Vintasoft.Twain.AcquireModalState.None
Do
acquireModalState1 = device.AcquireModal()
Select Case acquireModalState1
Case Vintasoft.Twain.AcquireModalState.ImageAcquired
Console.WriteLine("Image is acquired.")
If device.AcquiredImage IsNot Nothing Then
device.AcquiredImage.Dispose()
End If
' cancel image scan
device.CancelTransfer()
Exit Select
Case Vintasoft.Twain.AcquireModalState.ScanCompleted
Console.WriteLine("Scan is completed.")
Exit Select
Case Vintasoft.Twain.AcquireModalState.ScanCanceled
isScanCanceled = True
Console.WriteLine("Scan is canceled.")
Exit Select
Case Vintasoft.Twain.AcquireModalState.ScanFailed
Console.WriteLine(String.Format("Scan is failed: {0}.", device.ErrorString))
Exit Select
End Select
Loop While acquireModalState1 <> Vintasoft.Twain.AcquireModalState.None
If Not isScanCanceled Then
Throw New ApplicationException("Scan is NOT canceled.")
End If
' close the device
device.Close()
End Using
End Sub
End Class
namespace TwainExamples_CSharp
{
class SyncScan_Cancel
{
/// <summary>
/// This method scans one image and cancels image scan.
/// </summary>
public static void ScanOneImageAndCancelScan()
{
bool isScanCanceled = false;
// create the device manager
using (Vintasoft.Twain.DeviceManager deviceManager = new Vintasoft.Twain.DeviceManager())
{
deviceManager.IsTwain2Compatible = true;
// open the device manager
deviceManager.Open();
// get the device
string deviceName = "KODAK Scanner: i5000";
Vintasoft.Twain.Device device = deviceManager.Devices.Find(deviceName);
if (device == null)
throw new System.ApplicationException(string.Format("Device '{0}' is not found.", deviceName));
// disable device UI
device.ShowUI = false;
// specify that device must be closed after scan
device.DisableAfterAcquire = true;
// open the device
device.Open();
// specify that 2 images must be acquired from scanner
device.XferCount = 2;
// run asynchronous image acquisition
Vintasoft.Twain.AcquireModalState acquireModalState = Vintasoft.Twain.AcquireModalState.None;
do
{
acquireModalState = device.AcquireModal();
switch (acquireModalState)
{
case Vintasoft.Twain.AcquireModalState.ImageAcquired:
System.Console.WriteLine("Image is acquired.");
if (device.AcquiredImage != null)
device.AcquiredImage.Dispose();
// cancel image scan
device.CancelTransfer();
break;
case Vintasoft.Twain.AcquireModalState.ScanCompleted:
System.Console.WriteLine("Scan is completed.");
break;
case Vintasoft.Twain.AcquireModalState.ScanCanceled:
isScanCanceled = true;
System.Console.WriteLine("Scan is canceled.");
break;
case Vintasoft.Twain.AcquireModalState.ScanFailed:
System.Console.WriteLine(string.Format("Scan is failed: {0}.", device.ErrorString));
break;
}
}
while (acquireModalState != Vintasoft.Twain.AcquireModalState.None);
if (!isScanCanceled)
throw new System.ApplicationException("Scan is NOT canceled.");
// close the device
device.Close();
}
}
}
}
Requirements
Target Platforms: .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
See Also