public void Abort() { if (this.IsBusy) // если задача уже работает то прерываем команду, и там возникнет событие заверщения задачи и удалит сама поток { if (ExecutingCommand != null) { ExecutingCommand.Cancel(); } else if (workerThread != null) { workerThread.Abort(); workerThread = null; } } else // иначе просто удаляем из очереди { lock (Queue) { if (this.waitDialog != null && waitDialog.IsLoaded) { waitDialog.Close(); } Queue.Remove(this); } //WaitWindow.RepositionAllWindows(); } }
private void CommandThread() { while (IsRunning) { _commandReceivedEvent.WaitOne(); while (IsRunning && _commandQueue.TryDequeue(out string command)) { ExecutingCommand?.Invoke(this, new ExecutingCommandEventArgs(command)); _process.StandardInput.WriteLine(command); } _commandReceivedEvent.Reset(); } }