System.Windows.Forms.Timer and "thread" safety

  • Thread starter Thread starter Maxim
  • Start date Start date
M

Maxim

Greetings,


A newbie question.


I have 2 System.Windows.Forms.Timers in my app, I would like to know if
there is a risk that the assigned callback functions can be executed at
the same time.

For example, the first timer calls a function every 6 secondes, and the
second - every 7 seconds. What exactly happens at the 42 second for
example ? And what if a callback function's execution takes more than 1
second, and that another timer calls it's function at the same time ?

In my case, I would like to be sure that the Timer callback function
execution is linear, i.e., the they must not be executed at the same
time.

What do you think about it ?

Thank you !
 
From a thread safety perspective, you are OK with the Forms.Timer (that
cannot be said about the other two .NET timers of which one is supported by
the CF - threading.timer).

Remember that you can try it yourself and be sure of exactly what happens if
one activity takes longer than the other to complete... that is what I would
do rather than trust anybody else telling me what they think.

Without having more details of what exactly you are trying to do, I will
refrain form further comments...

Cheers
Daniel
 
They will be called in sequence. (Although which is called first is not
defined). The timer callbacks are on the same thread so they are naturally
synchronized.
 
Back
Top