C#DownloadFileAsync回调未被触发

时间:2011-08-20 15:44:24

标签: c# httpwebrequest webclient

出于某种原因,我指定的Async回调似乎没有被调用。我在原始应用程序线程启动的Thread中有以下内容:

WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += DownloadCompleted;
webClient.DownloadProgressChanged += DownloadProgressChanged;
webClient.DownloadFileAsync(new Uri(downloadUrl), tempPath);

对于我得到的回调:

public void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
    Console.WriteLine("progress");
}

public void DownloadCompleted(object sender, AsyncCompletedEventArgs e)
{
    Console.WriteLine("completed");
}

我使用断点来验证downloadUrl和tempPath字符串是否都有效(我可以在Windows资源管理器中看到下载的文件)。有关回调为何不会被触发的任何见解?谢谢!

0 个答案:

没有答案