Sunday 4 August 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...