如果一个定时器在新的周期时间到来之前不能完成它的所有工作怎么办? [英] What if a timer can not finish all its works before the new cycle time arrives?
问题描述
假设我们有一个每 10 分钟运行一次的计时器.如果它的处理周期超过 10 分钟怎么办.是否会为此启动一个新线程?它会中断当前的操作吗?如果单个对象在计时器内发生变异怎么办?
Suppose we have a timer which runs every 10 minutes. What if the cycle of its processing takes more than 10 minutes. Does a new thread starts for that? Will it interrupt its current operation? What if a single object is mutated inside the timer?
对不起,如果我没有提到任何代码,因为问题很清楚,而且我想从多线程编程极客的角度知道完整的答案,而不是通过尝试通过测试来找到松散的答案示例应用程序.其实我想知道它的工作机制背后的逻辑.
Sorry if I do not mention any code for that because the problem is clear and also I want to know the complete answer from the viewpoint of a multi-threaded programming geek rather than finding a loose answer by trying to test it via a sample application. Actually, I want to know the logic behind its working mechanism.
推荐答案
如果您正在使用 System.Threading.Timer
或 System.Timers.Timer
,计时器将再次打勾,开始一个新线程.请参阅 https://stackoverflow.com/a/10442117/56778 了解避免该问题的方法.
If you're using System.Threading.Timer
or System.Timers.Timer
, the timer will tick again, starting a new thread. See https://stackoverflow.com/a/10442117/56778 for a way to avoid that problem.
如果您正在使用 System.Windows.Forms.Timer
,那么在前一个完成处理之前不会发生新的勾号.
If you're using System.Windows.Forms.Timer
, then a new tick won't occur until the previous one is finished processing.
这篇关于如果一个定时器在新的周期时间到来之前不能完成它的所有工作怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!