主线程中点击某button
private void simpleButtonCopy_Click(object sender, EventArgs e)
{
this.simpleButtonCopy.Enabled = false;
this.simpleButtonCopy.Text = "复制中...";
Thread t1 = new Thread(new ThreadStart(CopyPics));
t1.Start();
}
线程运行函数
private void CopyPics()
{
if (this.simpleButtonCopy.InvokeRequired)
{
BeginInvoke(new NoObjectDel(FinishCopyPics));
}
else
{
FinishCopyPics();
}
}
private void FinishCopyPics()
{
this.simpleButtonCopy.Text = "复制";
this.simpleButtonCopy.Enabled = true;
}
调用函数可以简化下
private void CopyPics()
{
if (this.simpleButtonCopy.InvokeRequired)
{
this.Invoke(new NoObjectDel(CopyPics));
return;
}
this.simpleButtonCopy.Text = "复制";
this.simpleButtonCopy.Enabled = true;
}