8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

System.Windows.Forms.Timerの間隔

Posted at

タイマーを繰り返す処理を行ってみたところ、
回数が増えるに従ってハンドラーが呼ばれる間隔が長くなっていく現象に遭遇。
単にタイマーを呼び出すだけでを同じ現象が発生するのか確認してみました。
(タイマー間隔は500msec)
結果は、そうなるみたいです。

タイマー間隔調査結果.png

code
DateTime last;
TimeSpan ts;
int cnt;
void timer_Tick(object sender, EventArgs e)
{
if (cnt > 0)
{
ts += DateTime.Now - last;
}
cnt++;
last = DateTime.Now;

        if ((cnt % 50) == 0)
        {
            this.labelTimer.Text += string.Format("avg = {0}msec, cnt={1}", ts.TotalMilliseconds / cnt, cnt) + "\n";
            this.labelTimer.Update();
        }
    }
8
8
7

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?