private void LimitFPS() { var elapsed = _fpsLimiterWatch.Elapsed; var targetms = new TimeSpan(166666); var tdiff = (targetms - elapsed); if (tdiff.TotalMilliseconds >= 1) { FrameSleep.Sleep(Math.Min(5, (int)(tdiff.TotalMilliseconds))); _fpsLimiterWatch.Restart(); } else if (tdiff.Milliseconds < 0) { _fpsLimiterWatch.Restart(); } }