Thread timer

kesdesng

New member
Joined
Jan 12, 2015
Messages
4
Programming Experience
5-10
i need to create a thread timer which works every 1 second asynchronously
 
Are you actually saying that you want to initiate an action on a secondary thread every second? If so then you can use a System.Timers.Timer with its Interval set to 1000. As long as the SynchronizingObject property is set to null, it will raise its Elapsed event on a thread pool thread rather than the UI thread.
 
yes i am using System.Timers.Timer but i need to use System.Threading Timer because sometimes code line on timer_tick event takes longer than Interval time.
i wil try SynchronizingObject to null hope it works fine thank you.
 
yes i am using System.Timers.Timer but i need to use System.Threading Timer because sometimes code line on timer_tick event takes longer than Interval time.
i wil try SynchronizingObject to null hope it works fine thank you.

Um, no. The System.Timers.Timer doesn't even have a Tick event so if your Timer does have a Tick event then it's not a System.Timers.Timer; it's a System.Windows.Forms.Timer. You DO NOT need to use a System.Threading.Timer.
 
yes i am using System.Timers.Timer but i need to use System.Threading Timer because sometimes code line on timer_tick event takes longer than Interval time.
If the time needed for the process is longer than the interval, you can stop the timer in the Elapsed event handler, call your process and restart the timer when the process is finished (recalculating the required interval if needed).
 
Back
Top Bottom