1
我想倒數計時器開始滴答兩個半小時。我試過這個使用調度計時器在WP7中倒數計時器
請找到下面的代碼。但它沒有正確更新秒。它太快了。它一次剔2秒而不是1秒
private void DrawBlackout()
{
TextBlock videoText = new TextBlock();
dt = new DispatcherTimer();
dt.Interval = new TimeSpan(0,0,1); // 1 Seconds
dt.Tick += new EventHandler(dt_Tick);
dt.Start();
}
void dt_Tick(object sender, EventArgs e)
{
// do something
milliseconds = milliseconds - 1000;
label.Text = getTimeText(milliseconds/1000);
elapsed += 1000;
//Debug.WriteLine(stopwatch.ElapsedMilliseconds + "\n");
if (milliseconds <= 1000)
dt.Stop();
}
String getTimeText(long secVal)
{
String timeString = "";
int seconds = (int)(secVal % 60);
int minutes = (int)((secVal/60) % 60);
int hours = (int)((secVal/(60 * 60)) % 60);
if (hours <= 9)
timeString = "0" + Convert.ToString(hours) + " : ";
else
timeString = Convert.ToString(hours) + " : ";
if (minutes <= 9)
timeString = timeString + "0" + Convert.ToString(minutes) + " : ";
else
timeString = timeString + Convert.ToString(minutes) + " : ";
if (seconds <= 9)
timeString = timeString + "0" + Convert.ToString(seconds) + " ";
else
timeString = timeString + Convert.ToString(seconds) + " ";
return timeString;
}
請幫忙解決此問題。
它適合我! –
這是仿真器還是真實設備? –
而不是假設每個嘀嗒將恰好是1000毫秒,你應該節省開始時間,並在每個滴答聲看到自從開始以來已經過去了多少時間。然後你可以每隔100ms打勾一次,看起來應該很穩定。 –