Abruzzo Forte e Gentile
Abruzzo Forte e Gentile

Reputation: 14879

question about System.Windows.Forms.Timer

I am building a WinForms application reading from a socket data and charting lines. I am using System.Windows.Forms.Timer to trigger each second the event that

My Question is about the Timer object: I have one Timer object for each WinForm having a chart to redraws; so suppose I have 20 chart, I will have 20 forms with a total of 20 Timers.

Is this a good approach? I decided this based on the following(please correct me if I am wrong )

Are too much timers a good approach or could I have drawback? Thanks AFG

Upvotes: 0

Views: 528

Answers (3)

Michal Ciechan
Michal Ciechan

Reputation: 13898

Why not redraw the line straight away when the data is received by the socket?

Upvotes: 0

Benny
Benny

Reputation: 8815

maybe better approach is to use a worker thread to receive data and use event fired from that worker thread to notify the UI to redraw itself.

Upvotes: 1

SLaks
SLaks

Reputation: 888203

This is a good approach, although you might want to reuse the timers instead of making a separate timer for each form.
For example, you could make a static Timer object and add a Tick handler in the form constructor. Remember to unsubscribe from the event when the form closes (in Dispose or OnClose), or your forms will never die.

Upvotes: 2

Related Questions