J
JAM
I'm planning to use BacgroundWorker to get some task done. I would
like to update with progress some labels on the main Form.
Let's say I have label1, label2 and label3 on the Form.
BackgroundWorker seem to be working with progress bar from within it's
own thread with no problem. However updating any of the labels causes
exception. I understand that in order to update label1 I have to use
Invoke.
Is it possible to do the following:
(I skip delegate construct here for simplification)
label1.Invoke(updatelabels)
void updatelabels()
{
label1.Text = "abcd";
label2.Text = "aaaa";
label3.Text = "bbbb";
}
or do I have to write separate delegate for each label such as:
(again I skip three delegate constructs here for simplification)
label1.Invoke(updatelabel1);
label2.Invoke(updatelabel2);
label3.Invoke(updatelabel3);
void updatelabel1()
{
label1.Text = "abcd";
}
void updatelabel2()
{
label2.Text = "aaaa";
}
void updatelabel3()
{
label3.Text = "bbbb";
}
JAM
like to update with progress some labels on the main Form.
Let's say I have label1, label2 and label3 on the Form.
BackgroundWorker seem to be working with progress bar from within it's
own thread with no problem. However updating any of the labels causes
exception. I understand that in order to update label1 I have to use
Invoke.
Is it possible to do the following:
(I skip delegate construct here for simplification)
label1.Invoke(updatelabels)
void updatelabels()
{
label1.Text = "abcd";
label2.Text = "aaaa";
label3.Text = "bbbb";
}
or do I have to write separate delegate for each label such as:
(again I skip three delegate constructs here for simplification)
label1.Invoke(updatelabel1);
label2.Invoke(updatelabel2);
label3.Invoke(updatelabel3);
void updatelabel1()
{
label1.Text = "abcd";
}
void updatelabel2()
{
label2.Text = "aaaa";
}
void updatelabel3()
{
label3.Text = "bbbb";
}
JAM