I need help with setting/changing the value of a label in my C# program whenever I try it an error occurs saying I need to cross thread it all. Can anyone write some code to help me with that?
My code is:
int number = 0;
int repeats = Convert.ToInt32(textBox2.Text);
while (number < repeats)
{
repeats++;
label5.Text = "Requested" + repeats + "Times";
}
Can anyone help me?
Thanks.
Try the following to update the value
The Invoke method (from
Control.Invoke) will cause the passed in delegate to be run on the thread which the givenControlis affinitized to. In this case it will cause it to run on the GUI thread of your application and hence make the update safe.