C#中的计时器要怎么用,给个例子

来源:学生作业帮助网 编辑:作业帮 时间:2024/10/06 09:28:30
C#中的计时器要怎么用,给个例子
xS]kA+겉 4j/&ﲛf6̦)"4%)iEKԦ)613gv6|s=LrGpwNN?OtZ6O6S?bmX YV#fL(kBaU-U WA™$/R3n}qTF]- t 9(,%,Q@ *C|"+@9xsm0sCLբRU2Rp(6PEepw?x!k& Y`0f{BGG߂އd? ySXwD#Akl2E+#p:LSNGDRƺlS$b*{(F9. $9'el;?W$)$4d]Rx} ܳ(79u |d3FBKX6.A/BB |d.$ Lmd="5 e[ i

C#中的计时器要怎么用,给个例子
C#中的计时器要怎么用,给个例子

C#中的计时器要怎么用,给个例子
点击一个start的button开始计时,时间到时,就执行某个事件(theout),在这个例子里就show一下时间值.
System.Timers.Timer t = new System.Timers.Timer();//实例化Timer类
private void btnStart_Click(object sender, EventArgs e)
{
int intTime = Convert.ToInt32(cmbTimer.Text.ToString()) * 60 * 60 * 1000;
t.Interval = intTime;//设置间隔时间,为毫秒;
t.Elapsed += new System.Timers.ElapsedEventHandler(theout);//到达时间的时候执行事件;
t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
}
public void theout(object source, System.Timers.ElapsedEventArgs e)
{
MessageBox.Show(e.SignalTime.ToString());
}