110,532
社区成员
发帖
与我相关
我的任务
分享
using System;
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++;
}
}
}