VintaSoft Twain .NET SDK v10.2
EndOfJob Property (Device)
Example 




Vintasoft.WpfTwain Namespace > Device Class : EndOfJob Property
Detects the end of batch job.
Syntax
'Declaration
 
<BrowsableAttribute(False)>
<ReadOnlyAttribute(True)>
Public ReadOnly Property EndOfJob As Boolean
'Usage
 
Dim instance As Device
Dim value As Boolean
 
value = instance.EndOfJob
[Browsable(false)]
[ReadOnly(true)]
public bool EndOfJob {get;}
[Browsable(false)]
[ReadOnly(true)]
public: __property bool get_EndOfJob();
[Browsable(false)]
[ReadOnly(true)]
public:
property bool EndOfJob {
   bool get();
}

Property Value

true - end of batch job was reached; false otherwise.
Remarks
Value of this property is valid only:
Example
This example shows how to detect job separators during scanning.
Private _deviceManager As DeviceManager
Private _device As Device
Private _jobCounter As Integer = -1
            
Public Sub ScanImageWithJobControl()
    Try
        ' create and open device manager
        _deviceManager = New DeviceManager()
        _deviceManager.Open()
            
        ' get reference to the default device
        _device = _deviceManager.DefaultDevice
        ' subscribe to device events
        AddHandler _device.ImageAcquired, New EventHandler(Of ImageAcquiredEventArgs)(AddressOf _device1_ImageAcquired)
        AddHandler _device.ScanCompleted, New EventHandler(AddressOf _device1_ScanCompleted)
        AddHandler _device.ScanCanceled, New EventHandler(AddressOf _device1_ScanCanceled)
        AddHandler _device.ScanFailed, New EventHandler(Of ScanFailedEventArgs)(AddressOf _device1_ScanFailed)
        AddHandler _device.ScanFinished, New EventHandler(AddressOf _device1_ScanFinished)
            
        _device.ShowUI = False
        _device.DisableAfterAcquire = True
            
        ' open the device
        _device.Open()
            
        ' set scanning settings
        _device.JobControl = JobControl.DetectAndIncludeJobSeparatorAndContinueScanning
        _jobCounter = _jobCounter + 1
            
        ' acquire images from device
        _device.Acquire()
    Catch ex As TwainException
        Console.WriteLine(ex.Message)
    End Try
End Sub
            
Private Sub _device1_ImageAcquired(ByVal sender As Object, ByVal e As ImageAcquiredEventArgs)
    If _device.EndOfJob Then
        _jobCounter = _jobCounter + 1
    Else
        Try
            ' save the acquired image
            e.Image.Save(String.Format("c:\job{0}.tif", _jobCounter))
            
            ' dispose the acquired image
            e.Image.Dispose()
        Catch ex As ImagingException
            Console.WriteLine(ex.Message)
        End Try
    End If
End Sub
            
Private Sub _device1_ScanCompleted(ByVal sender As Object, ByVal e As EventArgs)
    Console.WriteLine("Scan is completed.")
End Sub
            
Private Sub _device1_ScanCanceled(ByVal sender As Object, ByVal e As EventArgs)
    Console.WriteLine("Scan is canceled.")
End Sub
            
Private Sub _device1_ScanFailed(ByVal sender As Object, ByVal e As ScanFailedEventArgs)
    Console.WriteLine(String.Format("Scan is failed: {0}", e.ErrorString))
End Sub
            
Private Sub _device1_ScanFinished(ByVal sender As Object, ByVal e As EventArgs)
    ' close the device
    _device.Close()
End Sub
DeviceManager _deviceManager;
Device _device;
int _jobCounter = -1;
            
public void ScanImageWithJobControl()
{
    try
    {
        // create and open device manager
        _deviceManager = new DeviceManager();
        _deviceManager.Open();
            
        // get reference to the default device
        _device = _deviceManager.DefaultDevice;
        // subscribe to device events
        _device.ImageAcquired += new EventHandler<ImageAcquiredEventArgs>(_device1_ImageAcquired);
        _device.ScanCompleted += new EventHandler(_device1_ScanCompleted);
        _device.ScanCanceled += new EventHandler(_device1_ScanCanceled);
        _device.ScanFailed += new EventHandler<ScanFailedEventArgs>(_device1_ScanFailed);
        _device.ScanFinished += new EventHandler(_device_ScanFinished);
            
        _device.ShowUI = false;
        _device.DisableAfterAcquire = true;
            
        // open the device
        _device.Open();
            
        // set scanning settings
        _device.JobControl = JobControl.DetectAndIncludeJobSeparatorAndContinueScanning;
        _jobCounter = _jobCounter + 1;
            
        // acquire images from device
        _device.Acquire();
    }
    catch (TwainException ex)
    {
        Console.WriteLine(ex.Message);
    }
}
            
private void _device1_ImageAcquired(object sender, ImageAcquiredEventArgs e)
{
    if (_device.EndOfJob)
        _jobCounter = _jobCounter + 1;
    else
    {
        try
        {
            // save the acquired image
            e.Image.Save(string.Format(@"c:\job{0}.tif", _jobCounter));
            
            // dispose the acquired image
            e.Image.Dispose();
        }
        catch (ImagingException ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
}
            
private void _device1_ScanCompleted(object sender, EventArgs e)
{
    Console.WriteLine("Scan is completed.");
}
            
private void _device1_ScanCanceled(object sender, EventArgs e)
{
    Console.WriteLine("Scan is canceled.");
}
            
private void _device1_ScanFailed(object sender, ScanFailedEventArgs e)
{
    Console.WriteLine(string.Format("Scan is failed: {0}", e.ErrorString));
}
            
void _device_ScanFinished(object sender, EventArgs e)
{
    // close the device
    _device.Close();
}
Requirements

Target Platforms: Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

See Also

Reference

Device Class
Device Members
JobControl Property