private void gameLoop() { _soccerPitch = new SoccerPitch(pictureBox1.ClientRectangle.Width, pictureBox1.ClientRectangle.Height); _simulationStarted = true; PrecisionTimer timer = new PrecisionTimer(ParameterManager.Instance.FrameRate); while (!_stopEvent.WaitOne(0, true)) { if (timer.ReadyForNextFrame() && !_simulationPaused) { _soccerPitch.Update(); } pictureBox1.Invalidate(); Thread.Sleep(1); } _soccerPitch = null; _simulationStarted = false; // a final call to repaint our current state pictureBox1.Invalidate(); }