Activating timer from other thread

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?
 
C

Cor Ligthert [MVP]

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
 
D

Diego F.

Sorry, I don't understand you. What do you mean by your idea?

--

Regards,

Diego F.
 
A

Andrew Christiansen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top