我希望得到一些幫助,下面的問題 - 你可以看到我的live poker blinds timer這個問題:計時器不更新regularily和「跳過」第二(Silverlight 4中DispatcherTimer)
主時鐘(盲定時器倒計時)開始在20:00關閉,然後跳到19:58。水平計時器(在屏幕頂部計數) - 同步開始,因此是第二次。
這裏是我的代碼:XAML:
TextBlock Text="{Binding TimeLeftInCurrentBlindFormatted}"
和我的比賽類:
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");
}
}
}
當計時器通過UI開始日期時間設置:
TimeStarted = DateTime.UtcNow;
我認爲這是事實上,Tick並不一定完全是秒,UI是滯後的以某種方式跳過秒,但兩個計時器同時在Tick事件中更新(TimeRunningForCurrentBlindFormatted(這是最早用過的時間)和TimeLeftInCurrentBlindFormatted)。
在我的開發系統上,定時器從20點到19點59分,然後到19點57分。
*歎爲觀止 - 感謝您的幫助! – Rodney 2010-08-11 07:50:17