Lusine Avanesyan
Lusine Avanesyan

Reputation: 3

Why using `System.Timers.Timer` can interfere the whole performance?

I'm using a method which is called for 2 timers as their elapsed event handlers and also this method is called in the constructor of my class. The body of that method is mainly in

Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
 { ... }));

I'm having some anomalies. What is better to use instead of a timer?

Upvotes: 0

Views: 184

Answers (2)

Fischermaen
Fischermaen

Reputation: 12458

It depends on how short the interval of the timers are and how much you are doing in the elapsed events. In addition there is a change to the UI thread every time one of the timers elapses.

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1500385

I've asked a couple of questions in the comment to the question, but to address:

I'm having some anomalies. What is better to use instead of a timer?

If you want to do something periodically in the Dispatcher thread, use DispatcherTimer instead. Then you don't need to marshal back to the UI thread, as the timer will "tick" in the Dispatcher thread already.

Upvotes: 3

Related Questions