Cross-thread operation not valid: Control 'progressBar1' accessed from a thread other than the thread it was created on
You will get following error when you try to update a windows form control from a separate thread.
"Cross-thread operation not valid: Control 'progressBar1' accessed from a thread other than the thread it was created on."
"Cross-thread operation not valid: Control 'progressBar1' accessed from a thread other than the thread it was created on."
This article guides you on how to overcome this problem.
Problem
To reproduce this error, insert a progress bar control (progressbar1) on your form and insert a button(btnStart).
Solution
Note how SetControlpropertyValue function is used above. Following is it's definition.
You can apply same solution to any windows control. All you have to do is, copy SetControlValueCallback delegate and SetControlPropertyValue function from above code. For example if you want to set property of a label, use SetControlPropertyValue function.
SetControlPropertyValue(Label1, "Text", i.ToString());