I am using the following code to create a timer in a separate thread. Trouble I am having is that the Timer_Tick event isn't firing. If I run it without the threading it fires fine.
{.... Thread buildTimer = new Thread(o => { createTimer((string)o); }); buildTimer.Start(cboRole.Text) ...} private void createTimer(string roleText) { System.Windows.Forms.Timer t1 = new System.Windows.Forms.Timer(); //Create New Timer For Updates int RoleID = mkmdtproxy.GetRoleID(roleText); t1.Tag = "blah" t1.Tick += Timer_Tick; t1.Interval = 5000; t1.Start(); } private void Timer_Tick(object sender, EventArgs e) { blah blah blah }
I did some reading and thought perhaps I should be using system.threading.timer,however I read here: http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx that this wasn't advised in Windows forms applications (which this is). So I guess my first question is:
Should I even be trying to multi-thread the timer? Potentially I could be in a position whereby 50 timers need to be created so I thought this would be the best way to tackle it.
Assuming I should, why is the tick event not firing?
Thank you