计时器停止在窗体应用程序中工作 [英] Timer stopped working in window form application
问题描述
Hi Team,
i我正在使用计时器在我的窗口表单应用程序中连续调用C#中的一些函数。但有些时间后大约一天(10天)它会停止工作,甚至它的tick事件是不工作。
有没有人知道如何识别我的计时器问题和建议来克服这个问题
提前谢谢
我尝试了什么:
i尝试通过另一个计时器滴答事件....
if(timer1.Enabled == false){timer1.Enabled = true; timer1.Start(); };
Hi Team,
i am using timer to continuous calling some functions in my window form application in C# .but Some randomly after some time like approx (10 days) it stopped working even its tick event is not working.
Do anyone have any idea how to identify my this problem of timer and suggestion to overcome this
Thanks in advance
What I have tried:
i tried this by putting another timer tick event ....
if (timer1.Enabled == false) { timer1.Enabled = true; timer1.Start(); };
推荐答案
如果您使用的是System.Timers.Timer
集合AutoReset = true
然后您不需要在代码中启用和启动:
Timer.AutoReset属性(System.Timers) [ ^ ]
If you are usingSystem.Timers.Timer
the setAutoReset = true
then you don't need to enable and start in your code:
Timer.AutoReset Property (System.Timers)[^]
Tick 事件会触发,但不会执行您告诉事件处理程序要执行的操作吗?
如果直接调用事件处理程序是否仍然有效?
您可以检查if(yourTimer.Tick == null)log(EventHandlerSubscriptionError);
那样你会知道〜不知怎的〜 [1]您的事件处理程序已取消订阅该事件。
The Tick event fires, but doesn't do what you told the event handler to do?
Does the event handler still work if called directly?
You can checkif(yourTimer.Tick == null) log(EventHandlerSubscriptionError);
That way you would know if ~somehow~[1] your event handler got unsubscribed from the event.
这篇关于计时器停止在窗体应用程序中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!