public bool ProcessBatch(BatchWorkflowProgress progress) { if (IsRunningBatch) { return(false); //throw new InvalidOperationException("ProcessBatch was called when already processing a batch"); } _progress = progress; try { IsRunningBatch = true; runWorkerThread = true; var token = _cancellationTokenSource.Token; _cancellationToken = new CancellationToken(false); _mainTask = new TaskFactory <bool>(token).StartNew(ProcessBatchTaskRunner, _cancellationToken); _mainTask.GetAwaiter().OnCompleted(DisposeTask); return(true); } catch (Exception exception) { Log.Error(exception, "ProcessBatch Exception"); } return(false); }
/// <summary> /// Handles the Click event of the startBatchConversionToolStripMenuItem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> private void startBatchConversionToolStripMenuItem_Click(object sender, EventArgs e) { if (_userConfigService.ProcessQueueLength == 0) { MessageBox.Show("Convert image list is empty!", "Nothing to do.", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } ConvertProgress.Minimum = 0; ConvertProgress.Maximum = 100; lblStatusLabel.Text = ""; _userConfigService.Config.OutputFileExtension = (cboxImageFormat.SelectedItem as ImageFormatModel).Extension; _userConfigService.Config.OutputDirectory = lnkOutputDirectory.Text; _converterService.InitBatch(_userConfigService.Config, _userConfigService.Config.OutputDirectory); var progress = new BatchWorkflowProgress(new Progress <ImageEncodingProgress>(Handler)); //ProgressBar. _converterService.ProcessBatch(progress); //UpdateMenuState(); }