private void runBtn_Click(object sender, EventArgs e) { if (_running) { // stop the thread if (_paused) { _manualEvent.Set(); } _turingRunnerThread.Abort(); } else { // get the machine thread running if (_utmFile.Length == 0 || _inputFile.Length == 0) { MessageBox.Show("Please specify a turing machine spec file and an input file."); return; } try { var machine = new TuringMachine(); _manualEvent = new ManualResetEvent(false); machine.LoadSpec(new StreamReader(_utmFile).ReadToEnd()); var runner = new TuringRunner(machine, new StreamReader(_inputFile).ReadToEnd(), _manualEvent); runner.RunEvent += (snder, args) => BeginInvoke(new EventHandler <TuringRunEventArgs>(OnRunEvent), new[] { snder, args }); _turingRunnerThread = new Thread(runner.Run) { Priority = ThreadPriority.BelowNormal, Name = "Turing Machine Runner" }; _turingRunnerThread.Start(); // starts in waiting mode _manualEvent.Set(); // release the thread } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void showMachineBtn_Click(object sender, EventArgs e) { if (_utmFile.Length == 0) { MessageBox.Show("Please specify a turing machine spec file."); return; } try { var machine = new TuringMachine(); machine.LoadSpec(new StreamReader(_utmFile).ReadToEnd()); ClearOutput(); WriteOutput(machine.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); } }