CancelTransfer() Метод (Device)
В этом разделе
Отправляет на устройство команду отмены текущего процесса сканирования (процесс сканирования не будет отменен сразу после выполнения этого метода).
Синтаксис
'Declaration
Public Sub CancelTransfer()
public void CancelTransfer()
public: void CancelTransfer()
public:
void CancelTransfer()
Исключения
Исключение | Описание |
DebuggerException | Выбрасывается, если используется .NET отладчик и для оценки функции требуется, чтобы все потоки выполнялись. |
Ремарки
Важно: передача не будет отменена сразу после выполнения этого метода, передача будет отменена при возникновении события ScanCanceled или когда метод AcquireModal вернет AcquireModalState.None.
Пример
Это C#/VB. NET-код показывает, как отменить текущую асинхронную передачу изображения.
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();
}
}
}
}
Требования
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
Смотрите также