public void BeginRun(ulong steps, CancelToken ct) { if (IsRunning) { return; } lock (runLocker) { if (runThread != null) { if (runThread.IsAlive) { runThread.Join(); } } this.ct = ct; runThread = new Thread(() => { timer.Start(); Machine.RunResult res = Machine.RunResult.None; for (; steps > 0 && !ct.Cancelled; --steps) { res = m.Step(); if (res != Machine.RunResult.None) { break; } } timer.Stop(); EndRun(this, null); }); runThread.Start(); } }
private void EndRun(object sender, EventArgs e) { result = m.LastRunResult; switch (result) { case Machine.RunResult.None: break; case Machine.RunResult.CancellationSignalled: Console.Write("Run aborted. "); break; case Machine.RunResult.IllegalInstruction: Console.Write($"Illegal instruction at {m.ProgramCounter}! "); break; } BigInteger newInstructionsExecuted = m.InstructionsExecuted; BigInteger diff = newInstructionsExecuted - instructionsExecuted; Console.WriteLine($"{diff.ToString("N0")} instructions executed."); instructionsExecuted += newInstructionsExecuted; Program.RestorePrompt(); }