作者spider1216 (顺着感觉走)
看板C_Sharp
标题DispatcherTimer使用问题
时间Sun Apr 24 17:06:35 2011
如果我现在有3个副程式 A.B.C 要自动循序执行
private DispatcherTimer t = new DispatcherTimer();
private DispatcherTimer t1 = new DispatcherTimer();
private DispatcherTimer t2 = new DispatcherTimer();
int main()
{
t.Interval = TimeSpan.FromSeconds(1);
t.Tick += new EventHandler(A);
t.Start();
}
void A(object sender, EventArgs e)
{
t1.Interval = TimeSpan.FromSeconds(1);
t1.Tick += new EventHandler(B);
t1.Start();
}
void B(object sender, EventArgs e)
{
t2.Interval = TimeSpan.FromSeconds(1);
t2.Tick += new EventHandler(C);
t2.Start();
}
void C(object sender, EventArgs e)
{}
=========================================================
这种写法可以经过1秒自动执行A,之後会执行B,在执行C
但是ABC自动执行一次後,在自动执行ABC第2次时候就会出现问题
出现问题为:此时B好像不只重复执行一次??
请问各位高手,为什麽会有这样的问题呢 希望有人可以帮我解答 感激不尽!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.117.179.144
1F:推 horngsh:你可以自己画一条数线,以1秒为刻度去算就知道了 04/24 21:02
2F:→ spider1216:不太懂意思?! 04/24 22:39
3F:推 tomex:这种阶层呼叫比较容易发生问题,不如各thread各自独立 04/27 13:29
4F:推 tomex:而你提供一个priority机制,用到时才让该thread执行! 04/27 13:29