2

カスタム アニメーションを使用して 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 のはずです。理由はわかりません。私が欠けているものはありますか?

ありがとう

4

1 に答える 1

3

ドキュメントには、タイマーの分解能は 1 ミリ秒ではなく、最小 10 ミリ秒であると記載されているはずです ;) そうではないようです。とにかく、最小のタイマー分解能は約 10 ミリ秒です。これが、起動する最小間隔です。

とにかく(申し訳ありませんが)なぜ1msが必要なのですか?私には役に立たないように聞こえます。アニメーションは、1 秒あたり約 25 ~ 60 回の更新で問題ないはずです。残りはとにかく目に見えません。

于 2010-03-09T11:33:45.640 に答える