Activating timer from other thread

  • Thread starter Thread starter Diego F.
  • Start date Start date
D

Diego F.

Hello. I have a multi threaded application (I use threadpool). The main
thread has some timers. In some circumstances, I need to activate one of
these timers from other thread.

I activate the timer with enabled property, but the tick event won't raise.

What's the problem with that? Any solution?
 
Diego,

One of the main purposes from using threads is that they are not working
synchonized but assynchroon.

If you now want a synchronized assynchroon sollution, than you should look
in my idea first to your solution. However just my idea.

Cor
 
Since you described using the 'Enabled' property on the timer, I see you're
using System.Windows.Forms.Timer. This is not good to use in multi-threaded
applications unless the timer is used entirely within the GUI thread (within
the form which contains the timer). Rather, use System.Threading.Timer
instead. It invokes a method of your choice asynchronously at the intervals
specified. Also, you could consider utilizing Threading.Sleep within a loop
on your thread to achieve timer like functionality.

Best regards,
Andrew
 
Back
Top