public void Stop() { //Stop the bot botWorker.Abort(); botWorker.Dispose(); botState = BotState.Free; }
private void startDebuggerButton_Click(object sender, RoutedEventArgs e) { switch (debugger.Status) { case WorkerStatus.Idle: if (vm.View == StackerView.Blocks) { vm.LS.FromBlocks(vm.GetList()); } else { vm.LS.Script = loliScriptEditor.Text; } if (debuggerTabControl.SelectedIndex == 1) { logRTB.Focus(); } vm.ControlsEnabled = false; if (!OB.OBSettings.General.PersistDebuggerLog) { logRTB.Clear(); } dataRTB.Document.Blocks.Clear(); if (!debugger.IsBusy) { debugger.RunWorkerAsync(); OB.Logger.LogInfo(Components.Stacker, "Started the debugger"); } else { OB.Logger.LogError(Components.Stacker, "Cannot start the debugger (busy)"); } startDebuggerButton.Content = "Abort"; debugger.Status = WorkerStatus.Running; break; case WorkerStatus.Running: if (debugger.IsBusy) { debugger.CancelAsync(); OB.Logger.LogInfo(Components.Stacker, "Sent Cancellation Request to the debugger"); } startDebuggerButton.Content = "Force"; debugger.Status = WorkerStatus.Stopping; break; case WorkerStatus.Stopping: debugger.Abort(); OB.Logger.LogInfo(Components.Stacker, "Hard aborted the debugger"); startDebuggerButton.Content = "Start"; debugger.Status = WorkerStatus.Idle; vm.ControlsEnabled = true; break; } }
private void _WorkerAbort(ref AbortableBackgroundWorker worker) { if (worker != null) { worker.Abort(); worker = null; Thread.Sleep(100); Progress.Visible = false; CancelWorker.Visible = false; } }
/// <summary> /// Closes TIA portal when closing the window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void OnWindowClosing(object sender, CancelEventArgs e) { // waiting for BackgroundWorker if (_WorkerUi != null && _WorkerUi.IsBusy) { if (!Toolbox.ShowWarning("Worker is busy. Abort worker and close window?", true)) { e.Cancel = true; return; } if (_WorkerUi != null) { _WorkerUi.Abort(); } } }
private void btnProcess_Click(object sender, EventArgs e) { try { if (_isWorking == false) { if (string.IsNullOrEmpty(txtInputDirectory.Text) || string.IsNullOrEmpty(txtOutputDirectory.Text)) { MessageBox.Show(@"Input and Output Directories Are Required.", @"CR2 To JPG", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (!Directory.Exists(txtInputDirectory.Text) || !Directory.Exists(txtOutputDirectory.Text)) { MessageBox.Show(@"One or more directories are invalid or don't exist", @"CR2 To JPG", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } SetFormWorking(true); pbProgress.Value = 0; string[] arrFiles; if (Settings.Subfolders) { arrFiles = Directory.GetFiles(txtInputDirectory.Text, "*.CR2", SearchOption.AllDirectories); if (Settings.ProcessJpeg) { arrFiles = arrFiles.Concat(Directory.GetFiles(txtInputDirectory.Text, "*.JPG")).ToArray(); } } else { arrFiles = Directory.GetFiles(txtInputDirectory.Text, "*.CR2"); if (Settings.ProcessJpeg) { arrFiles = arrFiles.Concat(Directory.GetFiles(txtInputDirectory.Text, "*.JPG")).ToArray(); } } var converterOptions = new ConverterOptions { Files = arrFiles, OutputDirectory = txtOutputDirectory.Text, Watermark = WmContext }; //MessageBox.Show(converterOptions.Files.Length.ToString()); pbProgress.Maximum = converterOptions.Files.Length; BwConverter.RunWorkerAsync(converterOptions); lblStatusValue.Text = @"Converting...0% (0/" + pbProgress.Maximum + @") - " + Settings.ImageProcessor; } else { BwConverter.Abort(); _isWorking = false; pbProgress.Value = pbProgress.Maximum; SetFormWorking(false); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), @"Error whilst converting", MessageBoxButtons.OK, MessageBoxIcon.Error); if (BwConverter.IsBusy) { BwConverter.Abort(); } } }