I would appreciate some help with the following issue - you can see this problem on my live poker blinds timer:
The main clock (Blind timer countdown) starts off on 20:00 and then jumps to 19:58. The Level timer (which counts up at top of screen) - starts off in synch and is therefore a second out.
Here is my code: XAML:
TextBlock Text="{Binding TimeLeftInCurrentBlindFormatted}"
and my Tournament class:
private DispatcherTimer timerBlind;
private DateTime? blindTimeStarted = null;
public DateTime? BlindTimeStarted
{
get
{
return blindTimeStarted;
}
set
{
if (blindTimeStarted != value)
{
blindTimeStarted = value;
OnPropertyChanged("BlindTimeStarted");
OnPropertyChanged("TimeLeftInCurrentBlind");
OnPropertyChanged("TimeLeftInCurrentBlindFormatted");
OnPropertyChanged("TimeRunningForCurrentBlind");
OnPropertyChanged("TimeRunningForCurrentBlindFormatted");
}
}
}
public TimeSpan TimeLeftInCurrentBlind
{
get
{
return BlindTimeStarted == null ? blindset.CurrentBlind.BlindDuration : BlindTimeStarted.Value.Add(blindset.CurrentBlind.BlindDuration).Subtract(DateTime.UtcNow.Subtract(TotalTimePausedForCurrentBlind));
}
}
public string TimeLeftInCurrentBlindFormatted
{
get { return Utils.FormatTime(TimeLeftInCurrentBlind); }
}
void Timer_Tick(object sender, EventArgs e)
{
if (IsTimerBlindRunning)
{
OnPropertyChanged("TimeRunningForCurrentBlindFormatted");
OnPropertyChanged("TimeLeftInCurrentBlindFormatted");
}
}
}
When the timer is started through the UI the datetime is set:
TimeStarted = DateTime.UtcNow;
I assume it is something to do with the fact that the Tick is not neccessarily exactly a second and the UI is lagging somehow and skipping a second, but both timers are updated in the Tick event at the same time (TimeRunningForCurrentBlindFormatted (which is the top Elapsed time) and the TimeLeftInCurrentBlindFormatted).
On my dev system the timer goes from 20:00 to 19:59 and then to 19:57.