public override void RunThread() { while (true) { while (!s.getwPressed()) { this.speed = s.getSpeed(); try { System.Threading.Thread.Sleep(10); } catch (ThreadInterruptedException e) { e.ToString(); } s.decreaseSpeed(1f); } } }
public void Press(Speedometer s, GearChanger gc) { this.pressedClutch = true; this.lastSpeed = s.getSpeed(); this.lastGear = gc.getGear(); //need to make this function unblocking if (gc.getGear() != 0) { new Thread(() => { Thread.CurrentThread.IsBackground = true; while (this.isClutchPressed()) //while engine isn't engaged { System.Threading.Thread.Sleep(10); s.decreaseSpeed(5f); } }).Start(); this.pressFinished = true; } }
public void BasicForm_KeyUp(object sender, KeyEventArgs e) { if (e.KeyValue == 81 && c.isClutchPressed()) { Action action = () => c.Release(s, gc); this.Invoke(action); new Thread(() => { Thread.CurrentThread.IsBackground = true; float value; switch (gc.getGear()) { case 1: value = 0.1f; break; case 2: value = 0.2f; break; case 3: value = 0.3f; break; case 4: value = 0.35f; break; case 5: value = 0.4f; break; case 6: value = 0.5f; break; default: value = 0.2f; break; } while (!s.getwPressed() && !c.isClutchPressed()) { System.Threading.Thread.Sleep(10); s.decreaseSpeed(value); } }).Start(); } else if (e.KeyValue == 87 && !c.isClutchPressed()) { s.setwPressed(false); new Thread(() => { Thread.CurrentThread.IsBackground = true; while (!s.getwPressed() && !c.isClutchPressed()) { System.Threading.Thread.Sleep(10); s.decreaseSpeed(0.3f); } }).Start(); } }