C# downloadstringasync方法的问题
想用DownloadStringAsync下载网页,为什么运行后没有反应?DownloadStringCompleted为什么不被触发?
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
public static void download(string url)
{
WebClient client = new WebClient();
client.DownloadStringCompleted += (sender, e) =>
{
if (!e.Cancelled && e.Error == null)
{
string textString = (string)e.Result;
Console.WriteLine(textString);
}
else
{
Console.WriteLine("oh!!!");
}
};
client.DownloadStringAsync(new Uri(url));
}
static void Main(string[] args)
{
download("http://www.baidu.com");
}
}
}