カスタム アニメーションを使用して Silverlight アプリケーションを開発しています。変数 animationCounter を 1 ミリ秒ごとに更新して、1 秒で値が 1000 になるようにします。DispatcherTimer と System.Threading.Timer を試しました。こちらです:
DispatcherTimer timer = new DispatcherTimer(); (...)
timer.Interval = new TimeSpan(0, 0, 0, 0, 1);
timer.Tick += new EventHandler(timer_Tick); (...)
(...)
void timer_Tick(object sender, EventArgs e)
{
animationCounter++;
Dispatcher.BeginInvoke(() => txtAnimationCounter.Text = animationCounter.ToString());
}
System.Threading.Timer を使用
System.Threading timer = null;
timer = new System.Threading.Timer(UpdateAnimationCounter, 0, 1);
void UpdateAnimationCounter(object state)
{
animationCounter++;
Dispatcher.BeginInvoke(() => txtAnimationCounter.Text = animationCounter.ToString());
}
どちらも 1 秒間に AnimationCounter を 100 前後に設定しています。1000 のはずです。理由はわかりません。私が欠けているものはありますか?
ありがとう