我已經編寫了一個應用程序,並使用了6個定時器,它們必須先後啓動,但這些定時器無法正常工作。我對定時器知之甚少。c中定時器的問題#
例如,timer1在應用程序中啓動併發生某些事情。那麼timer1必須永遠停止,並且timer2必須立即啓動,並在應用程序中發生。然後timer2必須永遠停止,timer3必須啓動等等。
請幫忙。
這裏是我的代碼:
int yyyy = 0;
void move()
{
yyyy++;
if (yyyy <= 1)
{
timer1.Start();
timer1.Interval = 15;
timer1.Tick += new EventHandler(timer_Tick1);
}
if (yyyy <= 2)
{
timer2.Start();
timer2.Interval = 15;
timer2.Tick += new EventHandler(timer_Tick2);
}
if (yyyy <= 3)
{
timer3.Start();
timer3.Interval = 15;
timer3.Tick += new EventHandler(timer_Tick3);
}
if (yyyy <= 4)
{
timer4.Start();
timer4.Interval = 15;
timer4.Tick += new EventHandler(timer_Tick4);
}
if (yyyy <= 5)
{
timer5.Start();
timer5.Interval = 15;
timer5.Tick += new EventHandler(timer_Tick5);
}
if (yyyy <= 6)
{
timer6.Start();
timer6.Interval = 15;
timer6.Tick += new EventHandler(timer_Tick6);
}
}
和:(定時器2爲例)。
(所有定時器的下面代碼都完全相同)。
int t = 0;
private void timer_Tick2(object sender, EventArgs e)
{
t++;
if (t <= 150)
{
// do somthing
}
else
timer2.Stop();
}
你有什麼問題..你是否希望其他計時器在之前的計時器滴答150次之前不啓動..那麼你根本不需要計時器..它看起來像普通的順序過程 – 2011-02-04 09:35:05