这是一段我程序中的下载网页的代码片断: // Create a new WebClient instance.
WebClient myWebClient = new WebClient();
label1.Text = "开始下载文件...";
byte[] myDataBuffer = myWebClient.DownloadData(remoteUrl);
//将buffer中的字节吗重新中文编码
string data = new string(System.Text.Encoding.GetEncoding("GB2312").GetChars(myDataBuffer));
label1.Text = "下载完毕!"下载一个网页很不错,但是遇到多个网页需要下载,比如说string remoteUrl[5],我尝试用for循环,运行时就会卡住请问怎么序列化下载这些网页好呢?
WebClient myWebClient = new WebClient();
label1.Text = "开始下载文件...";
byte[] myDataBuffer = myWebClient.DownloadData(remoteUrl);
//将buffer中的字节吗重新中文编码
string data = new string(System.Text.Encoding.GetEncoding("GB2312").GetChars(myDataBuffer));
label1.Text = "下载完毕!"下载一个网页很不错,但是遇到多个网页需要下载,比如说string remoteUrl[5],我尝试用for循环,运行时就会卡住请问怎么序列化下载这些网页好呢?
解决方案 »
- oracle 简单的关联表 查询语句,急!!!!
- Console.Write(ds.table[2].Rows[0][1].ToString();什么意思
- ArcGIS Engine怎么画图?
- 报表加where条件
- 关于文件。
- 如何完善 弹力球项目?? 打不到砖块,计分???
- c# toolStripButton.DoDragDrop拖动问题
- C#加解密
- 新手提问:准备用VS.net2003, 如何快速掌握在这个平台上的开发?
- DataList 生成的<table>为什么第一列是空的.
- DataSet Table 名
- 动态生成N组radio每组俩个如何取到选中的值 急啊!高分求答案!!!!!!!!!!!
wc.DownloadStringCompleted+=.....然后在事件里面处理
using System.Collections.Generic;
using System.Text;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
static int ok=0;
static void Main(string[] args)
{
string[] links = new string[] {"http://baidu.com","http://163.com","http://sohu.com" };
foreach (string s in links)
{
WebClient wc = new WebClient();
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri(s));
}
while (ok < 3) {
System.Threading.Thread.Sleep(100);//防止主线程结束程序
}
} static void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
Console.WriteLine(e.Result);
ok++;
}
}
}
对事件不是很熟悉~~~~
貌似BeginInvoke异步委托能解决~~