Class ScanController
The main entry point for scanning with NAPS2.
public class ScanController
- Inheritance
-
ScanController
Constructors
ScanController(ScanningContext)
Initializes a new instance of the ScanController class with the specified ScanningContext.
public ScanController(ScanningContext scanningContext)
Parameters
scanningContext
ScanningContext
Properties
PropagateErrors
Whether scan errors should be thrown when enumerating the IAsyncEnumerable result. True by default. If you set this to false, you will need to listen for the ScanError event to handle errors.
public bool PropagateErrors { get; set; }
Property Value
Methods
GetCaps(ScanDevice, CancellationToken)
Gets the capabilities of the scanning device. This includes valid values for scanning options and extra metadata beyond just the device name and id.
public Task<ScanCaps> GetCaps(ScanDevice device, CancellationToken cancelToken = null)
Parameters
device
ScanDeviceThe device to query for capabilities.
cancelToken
CancellationTokenA token used to cancel the operation.
Returns
- Task<ScanCaps>
GetCaps(ScanOptions, CancellationToken)
Gets the capabilities of the scanning device. This includes valid values for scanning options and extra metadata beyond just the device name and id.
public Task<ScanCaps> GetCaps(ScanOptions options, CancellationToken cancelToken = null)
Parameters
options
ScanOptionsThe options to use.
cancelToken
CancellationTokenA token used to cancel the operation.
Returns
- Task<ScanCaps>
GetDeviceList()
Gets a list of devices using the default driver for the system (WIA on Windows, Apple on Mac, SANE on Linux).
public Task<List<ScanDevice>> GetDeviceList()
Returns
- Task<List<ScanDevice>>
The device list.
GetDeviceList(Driver)
Gets a list of devices using the specified driver.
public Task<List<ScanDevice>> GetDeviceList(Driver driver)
Parameters
driver
DriverThe driver to use.
Returns
- Task<List<ScanDevice>>
The device list.
GetDeviceList(ScanOptions)
Gets a list of devices using the specified options. This is mainly just the driver but some other properties may affect the list of devices (e.g. TwainOptions.Dsm).
public Task<List<ScanDevice>> GetDeviceList(ScanOptions options)
Parameters
options
ScanOptionsThe options to use.
Returns
- Task<List<ScanDevice>>
The device list.
GetDevices(CancellationToken)
Gets an enumerable of devices using the default driver for the system (WIA on Windows, Apple on Mac, SANE on Linux). Depending on the driver this may yield devices incrementally or all at once.
public IAsyncEnumerable<ScanDevice> GetDevices(CancellationToken cancelToken = null)
Parameters
cancelToken
CancellationTokenA token used to cancel the operation.
Returns
- IAsyncEnumerable<ScanDevice>
The device enumerable.
GetDevices(Driver, CancellationToken)
Gets an enumerable of devices using the specified driver. Depending on the driver this may yield devices incrementally or all at once.
public IAsyncEnumerable<ScanDevice> GetDevices(Driver driver, CancellationToken cancelToken = null)
Parameters
driver
DriverThe driver to use.
cancelToken
CancellationTokenA token used to cancel the operation.
Returns
- IAsyncEnumerable<ScanDevice>
The device enumerable.
GetDevices(ScanOptions, CancellationToken)
Gets an enumerable of devices using the specified options. This is mainly just the driver but some other properties may affect the list of devices (e.g. TwainOptions.Dsm). Depending on the driver this may yield devices incrementally or all at once.
public IAsyncEnumerable<ScanDevice> GetDevices(ScanOptions options, CancellationToken cancelToken = null)
Parameters
options
ScanOptionsThe options to use.
cancelToken
CancellationTokenA token used to cancel the operation.
Returns
- IAsyncEnumerable<ScanDevice>
The device enumerable.
Scan(ScanOptions, CancellationToken)
Scans using the specified options and returns an enumerable of the scanned images.
If PropagateErrors is true (the default), enumerating the result will result in an error if there was a problem scanning. For example, if one page was successfully scanned and then there was a paper jam, the first scanned image will be yielded and then an exception will be thrown for the paper jam. Or if the scanner was offline an exception will be thrown as soon as the caller tries to start enumerating the results. You can get detailed progress information by subscribing to the relevant ScanController events.public IAsyncEnumerable<ProcessedImage> Scan(ScanOptions options, CancellationToken cancelToken = null)
Parameters
options
ScanOptionsThe options to use.
cancelToken
CancellationTokenA token used to cancel the operation.
Returns
- IAsyncEnumerable<ProcessedImage>
The scanned images enumerable.
Events
PageEnd
Occurs when scanning is done for a page and the scanned image is available. This can be called multiple times during a single Scan operation if it is a feeder scanner.
public event EventHandler<PageEndEventArgs>? PageEnd
Event Type
- EventHandler<PageEndEventArgs>?
PageProgress
Occurs when the progress changes for scanning a page.
public event EventHandler<PageProgressEventArgs>? PageProgress
Event Type
- EventHandler<PageProgressEventArgs>?
PageStart
Occurs when scanning starts for a page. This can be called multiple times during a single Scan operation if it is a feeder scanner.
public event EventHandler<PageStartEventArgs>? PageStart
Event Type
- EventHandler<PageStartEventArgs>?
ScanEnd
Occurs when a Scan operation has completed. If the scan ends due to an error, the Error property will be set on the event args. For more detailed diagnostics, set ScanningContext.Logger.
public event EventHandler<ScanEndEventArgs>? ScanEnd
Event Type
- EventHandler<ScanEndEventArgs>?
ScanStart
Occurs when a Scan operation is about to start.
public event EventHandler? ScanStart
Event Type
- EventHandler?