我的代码有问题我在c#中使用计时器 [英] i have problem in my code i use timer in c#
本文介绍了我的代码有问题我在c#中使用计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
i使用计时器的形式,但是当第一次使用时工作正常,但如果我第二次使用我的表格工作2次和相同,如果点击更多的工作3次..但是如果我关闭窗口并且只在一次时打开工作....
我的代码
这个按钮
hi
i use timer in form but when use first time work good but if i use second time my form work 2 time and same if click more work 3 time .. but if i close window and open work good just when once time ....
my code
this in button
timer.Interval = 1000;
timer.Enabled = true;
timer.Start();
timer.Tick += new EventHandler(timer_Tick);
方法
the method
public void timer_Tick(object sender, EventArgs e)
{
if (cb10.Checked)
{
if (DateTime.Now.DayOfWeek.ToString() == "Friday")
{
if (DateTime.Now.Hour.ToString() == cb1.SelectedItem.ToString())
{
timer.Stop();
timer.Enabled = false;
if (chb1.Checked == true)
{
c1.sErial("g");
}
if (cb2.Checked == true)
{
c1.sErial("e");
}
if (cb3.Checked == true)
{
c1.sErial("i");
}
if (cb3.Checked == true)
{
c1.sErial("a");
}
MessageBox.Show(DateTime.Now.DayOfWeek.ToString());
}
}}}
}
推荐答案
您的问题很明显。
因为你有
Your problem is fairly obvious.
Because you have
timer.Tick += new EventHandler(timer_Tick);
在你的按钮事件,您需要在实际事件中删除事件处理程序。
in your button event you need to remove the event handler in the actual event.
timer.Tick -= timer_Tick;
这可以解决问题。
This should solve the issue.
这篇关于我的代码有问题我在c#中使用计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文