public void Init(BackgroundOptions options) { _worker = new BackgroundWorker { WorkerSupportsCancellation = true, WorkerReportsProgress = true }; _worker.ProgressChanged += (o, eventArgs) => options.BackgroundProgressBar.Value = eventArgs.ProgressPercentage; options.BackgroundProgressBar.Value = 0; options.BackgroundStopButton.Text = "Прервать"; options.BackgroundStopButton.Enabled = true; options.BackgroundStopButton.Click += (sender, args) => { options.BackgroundStopButton.Text = "Ожидаем..."; options.BackgroundStopButton.Enabled = false; ShouldStop = true; }; _worker.RunWorkerCompleted += (o, eventArgs) => { options.BackgroundStopButton.Text = "Завершено"; options.BackgroundStopButton.Enabled = false; }; }
public void Init(BackgroundOptions options) { _form = new BackgroundProgressForm(); _worker = new BackgroundWorker { WorkerSupportsCancellation = true, WorkerReportsProgress = true }; _worker.ProgressChanged += (o, eventArgs) => { _form.progress.Value = eventArgs.ProgressPercentage; _form.console.Items.Add( eventArgs.UserState.ToString()); }; _worker.RunWorkerCompleted += (o, eventArgs) => { _form.stop.Text = Resources.WordFiller_FillTemplate_CloseForm; _form.stop.Click += (sender, args1) => _form.Close(); if (!options.IsAutoClose) return; var tim = new Timer(500); var elapsed = 0.0d; tim.Elapsed += (sender, args) => { elapsed += tim.Interval; _form.stop.Text = string.Format("{0} ({1})", Resources.WordFiller_FillTemplate_CloseForm,(int)((options.AutoCloseDelay - elapsed)/1000)); if (elapsed < options.AutoCloseDelay) return; tim.Stop(); _form.Close(); }; _form.stop.Click += (sender, args) => tim.Stop(); tim.Start(); }; _form.stop.Click += (sender, args) => { _form.console.Items.Add("Ожидается завершение текущей операции"); ShouldStop = true; }; _form.Load += (sender, args) => _worker.RunWorkerAsync(); }
public void Init(BackgroundOptions ops) { _backgroundStrategy = StrategyFactory.CreateStrategy(false); _backgroundStrategy.Init(ops); _backgroundStrategy.Worker.DoWork += (o, eventArgs) => DoRecognize(); DoScan(); _backgroundStrategy.Run(); }
private void scan_Click(object sender, EventArgs e) { if (Scanner.Instance.Valid) { if (!Scanner.Instance.HasScanner) Scanner.Instance.InitTwain(); if (!Scanner.Instance.HasScanner) { MessageBox.Show(Resources.NoScanners); return; } var ops = new BackgroundOptions { IsBackground = true, IsAutoClose = true, AutoCloseDelay = 10 }; Scanner.Instance.Init(ops); if (Scanner.Instance.Success) { _person = Scanner.Instance.FillPerson(_person); //if (scannedPerson != null) //{ //_person.Merge(scannedPerson); _linker.MoveDataFromObject(); //} } } }