1
카운트 다운 타이머가 2 시간 반 동안 똑딱 거리기를 원합니다. 디스패처 타이머를 사용하여이 작업을 시도했습니다.WP7의 카운트 다운 타이머
아래 코드를 찾으십시오. 그러나 초를 제대로 업데이트하지는 않습니다. 너무 빠릅니다. 한 번에 1 초가 아닌 2 초 틱입니다.
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;
}
이 문제를 해결하는 데 도움을주십시오.
그것은 나를 위해 잘 작동합니다! –
에뮬레이터 또는 실제 장치에 있습니까? –
각 틱이 정확히 1000ms라고 가정하기보다는 시작 시간을 줄여야하며 각 틱마다 시작 시간이 얼마나 경과했는지 확인해야합니다. 그렇다면 매 100ms마다 똑딱 거릴 수 있고 꽤 일관되게 보일 것입니다. –