Exemple #1
0
        private void _scanWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            switch (_scanMode)
            {
            case ScanningMode.Manual:
                System.Drawing.Image image = ScannerHelper.Scan();
                _scannedImages.Add(image);
                DisplayedPage = _scannedImages.Count - 1;
                e.Result      = image;
                break;

            case ScanningMode.Automatic:
                BackgroundWorker back = (BackgroundWorker)sender;
                while (!back.CancellationPending)
                {
                    back.ReportProgress(0);
                    this.Dispatcher.Invoke(() =>
                    {
                        ScanningWindows.ScanningAutomatic scan = (ScanningWindows.ScanningAutomatic)ContentArea.Content;
                        loadingOverlay.Visibility       = Visibility.Visible;
                        scan.btnStopScanning.Visibility = Visibility.Collapsed;
                        ReadyButton.Visibility          = Visibility.Collapsed;
                    });
                    System.Drawing.Image image2 = ScannerHelper.Scan();
                    _scannedImages.Add(image2);
                    DisplayedPage = _scannedImages.Count - 1;
                    this.Dispatcher.Invoke(() =>
                    {
                        ScanningWindows.ScanningAutomatic scan = (ScanningWindows.ScanningAutomatic)ContentArea.Content;
                        loadingOverlay.Visibility       = Visibility.Collapsed;
                        scan.btnStopScanning.Visibility = Visibility.Visible;
                    });
                    for (int i = 1; i <= Convert.ToInt32(e.Argument) * 10; i++)
                    {
                        if (!back.CancellationPending)
                        {
                            System.Threading.Thread.Sleep(100);
                            back.ReportProgress(i);
                        }
                    }
                }
                break;
            }
        }