//简单的引出多线程是肿么回事儿。。。。当点击下载的时候,下载内容还没结束也可以点击资源库,其实这就用了另一个线程,弹出“下载完成”对话框的时候,没有点击确定是不能点击主页面内容的,这就是用------Action action = new Action(Msg); this.Invoke(action);------把对话框交给主页面去处理
namespace Windows多线程
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnDownload_Click(object sender, EventArgs e)
{
this.backgroundWorker1.RunWorkerAsync();
}
private void btnZiYuanKu_Click(object sender, EventArgs e)
{
MessageBox.Show("精彩大片,应有尽有");
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 30320; i < 30340; i++)
{
try
{
WebClient client = new WebClient();
client.DownloadFile(@"http://job.cnblogs.com/offer/" + i + "/", @"E:movices" + i + ".html");
}
catch (Exception ex)
{ }
}
Action action = new Action(Msg);
this.Invoke(action);
}
private void Msg()
{
MessageBox.Show("下载成功");
}
}
}