public void UpdateLogic(object sender, EventArgs e) { Stopwatch Watch = new Stopwatch(); Watch.Start(); long startTime = DateTime.Now.Millisecond; Input.update(); //float tpf = (startTime - lastTick) == 0 ? 0.16f : 1f / ((startTime - lastTick)*1000f); if (HasFocus) { appStateManager.processAppStates(tpf, startTime); //ForceDraw(); this.InvalidateVisual(); this.InvalidateMeasure(); this.InvalidateArrange(); this.UpdateDefaultStyle(); this.UpdateLayout(); //this.Focus(); } lastTick = startTime; int sleepTime = (int)(15 - (startTime - lastTick)); if (sleepTime < 0) { sleepTime = 0; } else if (sleepTime > 15) { sleepTime = 15; } //Debug.WriteLine(DateTime.Now.Millisecond - lastTick); System.Threading.Thread.Sleep((int)(15 - (startTime - lastTick))); Watch.Stop(); TimeSpan ts = Watch.Elapsed; tpf = (float)ts.TotalSeconds; //Debug.WriteLine(tpf); //System.Threading.Thread.Sleep((int)sleepTime); }