1. progressBar1在窗体中定义。
private void button1_Click(object sender, EventArgs e)
{
CopyFile(textBox1.Text, textBox2.Text + str, 1024, progressBar1);
}public void CopyFile(string FormerFile, string toFile, int SectSize, ProgressBar progressBar1)
{
.....
}这里传进去的progressBar1参数没有以ref关键字传,为什么在CopyFile中的progressBar1修改了窗体中的progressBar1的值
2.
这样调用线程,直接调用
{
thdAddFile = new Thread( new ThreadStart( RunAddFile ) );//创建一个线程
thdAddFile.Start();//执行当前线程
}和这样调用,通过在线程上执行委托 有什么 不同
{
thdAddFile = new Thread( new ThreadStart( SetAddFile ) );//创建一个线程
thdAddFile.Start();//执行当前线程}
求详解,为什么第2种方法在运行时候窗体上的button不能响应,但是窗体能够连续响应。
public delegate void AddFile();//定义委托
public void SetAddFile()
{
this.Invoke(new AddFile(RunAddFile));//在线程上执行指定的委托
}
public void RunAddFile()
{
CopyFile(textBox1.Text, textBox2.Text + str, 1024, progressBar1);//复制文件
thdAddFile.Abort();//关闭线程
}
private void button1_Click(object sender, EventArgs e)
{
CopyFile(textBox1.Text, textBox2.Text + str, 1024, progressBar1);
}public void CopyFile(string FormerFile, string toFile, int SectSize, ProgressBar progressBar1)
{
.....
}这里传进去的progressBar1参数没有以ref关键字传,为什么在CopyFile中的progressBar1修改了窗体中的progressBar1的值
2.
这样调用线程,直接调用
{
thdAddFile = new Thread( new ThreadStart( RunAddFile ) );//创建一个线程
thdAddFile.Start();//执行当前线程
}和这样调用,通过在线程上执行委托 有什么 不同
{
thdAddFile = new Thread( new ThreadStart( SetAddFile ) );//创建一个线程
thdAddFile.Start();//执行当前线程}
求详解,为什么第2种方法在运行时候窗体上的button不能响应,但是窗体能够连续响应。
public delegate void AddFile();//定义委托
public void SetAddFile()
{
this.Invoke(new AddFile(RunAddFile));//在线程上执行指定的委托
}
public void RunAddFile()
{
CopyFile(textBox1.Text, textBox2.Text + str, 1024, progressBar1);//复制文件
thdAddFile.Abort();//关闭线程
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货