Reputation: 14879
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 )
Forms.Timer
instance doesn't create a Thread on my application, but just triggers the event on receiving a WM_TIMER event from the message pump of the Form.Are too much timers a good approach or could I have drawback? Thanks AFG
Upvotes: 0
Views: 528
Reputation: 13898
Why not redraw the line straight away when the data is received by the socket?
Upvotes: 0
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
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