Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Timer tick event not firing when run in a separate thread

$
0
0

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


 

Viewing all articles
Browse latest Browse all 12583

Trending Articles