我有一個C#表單,它繪製了一些曲線。我試圖用隨機值以指定的間隔繪製這些曲線。我能夠做我想做的事,但有一種我無法回答的情況。在下面的情況下,儘管事實上我使用了5秒的時間間隔,但情況1的表格重新繪製得非常快。但是,在情況2中,如果我移動了「Invalidate();」到另一部分,那麼代碼就像它應該的那樣工作。 這種情況的原因是什麼?C#定時器滴答事件工作原理
謝謝...
案例1:
private void hizlariHesapla()
{
if (RastgeleDegerCheckBox.Checked == false)
{
// Some code blocks
}
else
{
// Some code blocks
Invalidate();
}
Hesapla(); // Not important for the case
}
private void SurekliCizdir_Tick_1(object sender, EventArgs e)
{
if (RastgeleDegerCheckBox.Checked == true)
{
hizlariHesapla();
}
}
案例2:
private void hizlariHesapla()
{
if (RastgeleDegerCheckBox.Checked == false)
{
// Some code blocks
}
else
{
// Some code blocks
}
Hesapla(); // Not important for the case
}
private void SurekliCizdir_Tick_1(object sender, EventArgs e)
{
if (RastgeleDegerCheckBox.Checked == true)
{
hizlariHesapla();
Invalidate();
}
}
請在初始化定時器的位置顯示代碼。 – Fischermaen 2012-01-05 20:35:39
它由Visual Studio生成的InitializeComponent()方法初始化。 – 2012-01-05 21:00:23
你有沒有選擇'Interval'? – Fischermaen 2012-01-05 21:21:22