Alex
Alex

Reputation: 11147

timer on thread?

Can i create successfully a timer clock on a thread? i'm creating one but it doesn't seem to work that well. My app is a multi-thread app that has to start a timer on a thread when ever a certain event happens. The timer is placed in every client connection. The clock doesn't work until i close my winform(i don't know why) . Is there anything in particular that i should know about timers in threads ?

Here is my timer code :

timer1.Interval = 1000;
timer1.Tick += new EventHandler(timer_Tick);
timer1.Enabled = true;
timer1.Start();

Upvotes: 1

Views: 701

Answers (2)

mggSoft
mggSoft

Reputation: 1042

Try this:

public void EnableTimer()
        {
            if (this.InvokeRequired)
                this.Invoke(new Action(EnableTimer));
            else
                this.timer1.Enabled = true;
        }

Upvotes: 0

Thorsten Dittmar
Thorsten Dittmar

Reputation: 56727

You might try to use System.Threading.Timer, which is basically a timer that's in a separate thread. You might also consider using a WaitHandle that's never fired and then using WaitOne(1000, false) to wait for a second.

Upvotes: 4

Related Questions