我找不到答案:
“跨线程操作无效:控件'progressBar1'从创建它的线程以外的线程访问。”
这是我的代码:
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;
}
}