六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 48|回复: 0

c#多线程处理界面

[复制链接]

升级  74.2%

2220

主题

2220

主题

2220

主题

榜眼

Rank: 8Rank: 8

积分
6710
 楼主| 发表于 2013-1-19 04:09:10 | 显示全部楼层 |阅读模式
主线程中点击某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;
}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表