user209293
user209293

Reputation: 889

timers.timer not firing exactly

I am using timers.timer to fire an event at every 5 seconds. What i noticed is after some time it is firing at every 6 seconds. There are lot of other threads running parallely. The timers.timer event will be generated using threadpool.The drift is because of other threads running paralley. Is that correct? my app is wpf app. I can't use dispatcher timer since it might affect UI.

I want to fire a timer event at every 5 seconds irrespetive of othere threads and without affecting UI. What are the solutios/best approaches.

Upvotes: 1

Views: 396

Answers (1)

Shekhar_Pro
Shekhar_Pro

Reputation: 18430

I am not sure about why is this happening but timer.timer is not ment for that purpose. if you are going to have many concurrently running timers on different threads then consider using System.Threading.Timer .

System.Threading.Timer is a simple, lightweight timer that uses callback methods and is served by thread pool threads. It is not recommended for use with Windows Forms, because its callbacks do not occur on the user interface thread. System.Windows.Forms.Timer is a better choice for use with Windows Forms. For server-based timer functionality, you might consider using System.Timers.Timer, which raises events and has additional features. have a look at

http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx

Upvotes: 1

Related Questions