开发者

timer on thread?

开发者 https://www.devze.com 2023-01-25 13:00 出处:网络
Can i create successf开发者_如何学Goully 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 ev

Can i create successf开发者_如何学Goully 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();


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.


Try this:

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

精彩评论

暂无评论...
验证码 换一张
取 消