private void DoTransfer(ScannedImageSource.Concrete source, WiaDevice device, WiaItem item) { if (ScanProfile.PaperSource != ScanSource.Glass && !device.SupportsFeeder()) { throw new NoFeederSupportException(); } if (ScanProfile.PaperSource == ScanSource.Duplex && !device.SupportsDuplex()) { throw new NoDuplexSupportException(); } InitProgress(device); ConfigureProps(device, item); using (var transfer = item.StartTransfer()) { int pageNumber = 1; transfer.PageScanned += (sender, args) => { try { using (args.Stream) { if (args.Stream.Length == 0) { return; } using (var output = Image.FromStream(args.Stream)) { ProduceImage(source, output, ref pageNumber); } } } catch (Exception e) { ScanException = e; } }; transfer.Progress += (sender, args) => smoothProgress.InputProgressChanged(args.Percent / 100.0); using (CancelToken.Register(transfer.Cancel)) { transfer.Download(); if (device.Version == WiaVersion.Wia10 && ScanProfile.PaperSource != ScanSource.Glass) { // For WIA 1.0 feeder scans, we need to repeatedly call Download until WIA_ERROR_PAPER_EMPTY is received. try { while (!CancelToken.IsCancellationRequested) { transfer.Download(); } } catch (WiaException e) when(e.ErrorCode == WiaErrorCodes.PAPER_EMPTY) { } } } } }