C# downloadstringasync方法的问题

lb041125 2011-11-05 03:50:05
想用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");
}

}
}

...全文
184 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧