Sunday, August 4, 2019

c# - Cross-thread operation not valid: Control 'progressBar1' accessed from a thread other than the thread it was created on

I couldn't find an answer for this:




"Cross-thread operation not valid: Control 'progressBar1' accessed

from a thread other than the thread it was created on."




This is my code:



        private void buttonStart_Click(object sender, EventArgs e)
{
ClassCopy cb = new ClassCopy();
cb.startCopy(textBoxSrc.Text, textBoxDest.Text, true);


th = new Thread(loading);
th.Start();

}

private loading()
{
for (int i = 0; i < 100; i++)
{
if (progressBar1.InvokeRequired)

progressBar1.Invoke(new Action(loading));
else
progressBar1.Value = i;
}
}

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...