public void ResetTick() { using (_timeLock.NewWriteLock()) { _startTick = PerformanceCounter.GetCurrent(); _lastTick = _startTick; } }
private void WorkerThreadProc(object param) { ResetTick(); while (_shouldContinue) { var isSuspended = IsSuspended; GameTime gameTime; if (!isSuspended) { var nowTick = PerformanceCounter.GetCurrent(); double delta, total; using (_timeLock.NewReadLock()) { delta = PerformanceCounter.GetDuration(_lastTick, nowTick); total = PerformanceCounter.GetDuration(_startTick, nowTick); } gameTime = new GameTime(TimeSpan.FromMilliseconds(delta), TimeSpan.FromMilliseconds(total)); Update(gameTime); Time = gameTime; _lastTick = nowTick; } else { gameTime = Time; } Draw(gameTime); if (!isSuspended) { while (_actionQueue.Count > 0) { var item = _actionQueue.Dequeue(); item.Action(item.State); } } } _exitingEvent.Set(); }