Windows.Forms.Timer instance and UI threads
Posted
by David Rutten
on Stack Overflow
See other posts from Stack Overflow
or by David Rutten
Published on 2010-04-18T18:56:27Z
Indexed on
2010/04/18
19:03 UTC
Read the original article
Hit count: 335
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.
© Stack Overflow or respective owner