在编写小软件的过程中,用到了线程操作。但是其中有一个问题是,创建的子线程想修改主程序的textBox的内容,原先的想法就是在子进程调用的函数中直接修改主程序的textBox属性,但是得到的结果是:程序崩溃。原因是线程间进行了不安全的调用……代码如下:
private void downloadFile()
{
DownloadClass dd = new DownloadClass();
string temp;
temp = fs.ReadLine();
while (temp!=null)
{
dd.StrUrl = temp;
dd.StrFileName = fileSavePath + "\\" + dealPicName(temp);
dd.DownloadFile();
tBoxResult.AppendText(dd.strError + "\n");
temp = fs.ReadLine();
}
MessageBox.Show("下载工作圆满完成!", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
//使用线程技术<