public void AddBlock(String label, TimeSpan time) { if (HasStarted) { return; } var interval = new IntervalBlock(); interval.CenterText = label; interval.CurrentTime = time; interval.OnFinished += delegate(object o, EventArgs args) { _elapsedTime = _elapsedTime.Add(interval.OriginalTime); if (Blocks.Count == Blocks.Count(b => b.HasFinished)) { Stop(); HasFinished = true; var oldBlock = CurrentBlock; Blocks.RemoveAt(0); Blocks.Add(oldBlock); } else { StartNextBlock(); } Common.PlaySound(Common.AlertSound1); }; RemainingTime = RemainingTime.Add(interval.CurrentTime); _orignalTime = RemainingTime; // keep the original time in memory so we can substract when running Blocks.Add(interval); }
/// <summary> /// Starts the timer. /// </summary> private void StartTimer() { _timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.DataBind, delegate { if (_remainingTime == TimeSpan.Zero) { _timer.Stop(); MainWindow.Instance.TimerExpire(); ((QuizViewModel)CurrentPage).GotoResultView(); } RemainingTime = RemainingTime.Add(TimeSpan.FromSeconds(-1)); }, Application.Current.Dispatcher); _timer.Start(); }
private void ClearSlot(TimeSpan talkDuration) { RemainingTime = RemainingTime.Add(talkDuration); CurrentSlotPointer = CurrentSlotPointer.Subtract(talkDuration); }