两个时间控件冲突,改用多线程怎么写?
有两个时间控件,一个是1秒1次,一个3秒触发一次,如果时间的事件里程序代码少的话还正常,但如果执行过多的时候,代码就会走不完,我想用多线程控制一下,可惜我不会用,谁能把以下代码改为多线程的,小弟谢谢了,或者有别的办法也行。
代码如下
class Class1
{
System.Timers.Timer aTimer;
System.Timers.Timer aTimer1;
public void test()
{
aTimer = new System.Timers.Timer();
aTimer.Enabled = true;
aTimer.Interval = 1000;
aTimer.Elapsed += new System.Timers.ElapsedEventHandler(aTimer_Elapsed);
GC.KeepAlive(aTimer);
aTimer1 = new System.Timers.Timer();
aTimer1.Enabled = true;
aTimer1.Interval = 3000;
aTimer1.Elapsed += new System.Timers.ElapsedEventHandler(aTimer1_Elapsed);
GC.KeepAlive(aTimer1);
}
void aTimer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
c();
}
void aTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
d();
}
public void c()
{
System.IO.FileStream fs = new System.IO.FileStream( "d:\\c.txt ", System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.Read);