Windows.Forms.Timer instance and UI threads
- by David Rutten
I have a custom control whose primary purpose is to draw data. I want to add a ScheduleUpdate(int milliSeconds) method to the control which will force an update X milliseconds from now.
Since this is all GUI land, I should be using a Windows.Forms.Timer, but how does this timer instance know which thread it belongs to? What if ScheduleUpdate() is called from a non-UI thread?
Should I construct the timer in the Control constructor? Or perhaps the Load event? Or is it safe to postpone construction until I'm inside ScheduleUpdate()?
I know there are some very similar questions about this already, but I don't have a Timer component on my control, I'm constructing it on a when-it's-needed basis.