Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 views
in Technique[技术] by (71.8m points)

c# - What if a timer can not finish all its works before the new cycle time arrives?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

If you're using System.Windows.Forms.Timer, then a new tick won't occur until the previous one is finished processing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...