Timer.Elapsed事件每次都执行两次

ahhbjz1 2012-09-12 04:32:57
代码如下:

private System.Timers.Timer timer1;

Form加载时:
//下载上传分开
timer1 = new System.Timers.Timer();
string str = cpm.GetConfig("TimerInteval");
dTimeInteval = cpm.StringToDouble(str);
timer1.Interval = dTimeInteval;
timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Elapsed);
timer1.Enabled = true;


void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
MessageBox.Show("+++++++++++++++++");
}

运行时,每次都输出两次,请大侠指点下什么原因,感谢
...全文
579 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
王子文龙 2012-09-14
  • 打赏
  • 举报
回复
有一次我用Dev的SpinEdit,当值改变的时候也是执行两次,一点原因找不到,后来换了个控件好了
cheng2005 2012-09-13
  • 打赏
  • 举报
回复
自己看看
timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Elapsed);
执行了几次
ahhbjz1 2012-09-12
  • 打赏
  • 举报
回复
就两个地方,一个是定义,一个是引用
qldsrx 2012-09-12
  • 打赏
  • 举报
回复
鼠标对着timer1_Elapsed点右键,查找所有引用,看看哪些地方被注册了.
ahhbjz1 2012-09-12
  • 打赏
  • 举报
回复
autoReset还是一样输出两次。。
ahhbjz1 2012-09-12
  • 打赏
  • 举报
回复
timer1.Elapsed只+了一次,而且两次输出是同时的,试试AutoReset吧,感谢
ahhbjz1 2012-09-12
  • 打赏
  • 举报
回复
timer1_Elapsed只绑定了一次,两次输出基本上是同时的

AutoReset 设置为 false后不是只能触发一次事件吗,第二次是随机的
缘中人 2012-09-12
  • 打赏
  • 举报
回复
不是时间到了触发的?Interval 这个设置大一些试试,
如果真是两次,第一次触发后开始跟踪能跟踪出来不
  • 打赏
  • 举报
回复
如果将 Enabled 设置为 true 并将 AutoReset 设置为 false,则 Timer 在第一次达到间隔时仅引发一次 Elapsed 事件。

设置一下
timer1.AutoReset = false;
cheng2005 2012-09-12
  • 打赏
  • 举报
回复
timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Elapsed);
自己找找Elapsed += 了多少次。
bdmh 2012-09-12
  • 打赏
  • 举报
回复
你是不是还有其他地方进行了事件绑定 xxxx.Elapsed += timer1_Elapsed,+=几次就会被执行几次

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧