WebClientを使用して非同期HTTP GETリクエストを作成しようとしていますが、登録されたコールバックが呼び出されることはありません。私はまた、同期を試してみました、そしてそれは正常に働いた。私は間違って何をしていますか?WebClientのDownloadStringCompletedイベントハンドラが呼び出されません
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'を終了していますか? – BrokenGlass
Eh。ありがとう、これは問題でした。 – norbip