Windows多线程
//简单的引出多线程是肿么回事儿。。。。当点击下载的时候,下载内容还没结束也可以点击资源库,其实这就用了另一个线程,弹出“下载完成”对话框的时候,没有点击确定是不能点击主页面内容的,这就是用------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(@"https://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("下载成功");
}
}
}