【发布时间】:2011-09-10 16:54:07
【问题描述】:
我正在尝试使用 Webclient 发出异步 HTTP GET 请求,但是,注册的回调永远不会被调用。我也尝试过同步的,效果很好。我做错了什么?
WebClient asyncWebRequest;
public AsyncWebRequest(Uri url)
{
asyncWebRequest = new WebClient();
url = new Uri("http://www.google.com/");
// string test = asyncWebRequest.DownloadString(url); // this works
asyncWebRequest.DownloadStringCompleted += new DownloadStringCompletedEventHandler(asyncWebRequest_DownloadStringCompleted);
asyncWebRequest.DownloadStringAsync(url);
}
void asyncWebRequest_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
throw new NotImplementedException();
}
【问题讨论】:
-
我猜您是在控制台应用程序中对此进行测试并在下载完成之前退出
Main? -
嗯。谢谢,这就是问题所在。