A
Axel Dahmen
Hi,
I've written a small tool using two threads:
a) GUI thread
b) Worker thread
The worker thread doesn't seem to be able to start the first thread's timer object. Can somebody please enlighten me why this happens?
This is what I did:
Created a form, added a Timer control, added a timer event handler to the form.
Within InitializeComponent() I set...
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.timer1.Interval = 100;
this.timer1.Tick = new System.EventHandler(this.timer1_Tick);
this.timer1.Enabled = false;
When the second thread finishes, it enables the timer to update some flags and to start an animation:
private void FinishedWork()
{
this.timer1.Enabled = true;
}
private void timer1_Tick(object sender, System.EventArgs e)
{
...
Invalidate();
}
But this doesn't start the timer! timer1_Tick() is never called!
If I enable the timer from within the first thread, everything works fine.
Why can't I start the timer from within the second thread? Is there an alternative approach for re-activating the first thread after the work has been done? In the end I will have x worker processes, each supposed to reactivate the timer of a control they are associated with. (Each control will start its own worker process and show the result when finished.)
TIA,
Axel Dahmen
I've written a small tool using two threads:
a) GUI thread
b) Worker thread
The worker thread doesn't seem to be able to start the first thread's timer object. Can somebody please enlighten me why this happens?
This is what I did:
Created a form, added a Timer control, added a timer event handler to the form.
Within InitializeComponent() I set...
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.timer1.Interval = 100;
this.timer1.Tick = new System.EventHandler(this.timer1_Tick);
this.timer1.Enabled = false;
When the second thread finishes, it enables the timer to update some flags and to start an animation:
private void FinishedWork()
{
this.timer1.Enabled = true;
}
private void timer1_Tick(object sender, System.EventArgs e)
{
...
Invalidate();
}
But this doesn't start the timer! timer1_Tick() is never called!
If I enable the timer from within the first thread, everything works fine.
Why can't I start the timer from within the second thread? Is there an alternative approach for re-activating the first thread after the work has been done? In the end I will have x worker processes, each supposed to reactivate the timer of a control they are associated with. (Each control will start its own worker process and show the result when finished.)
TIA,
Axel Dahmen