San*_*sal 1 c# webclient downloadfileasync
我有一个WPF应用程序,我想下载一个文件.
我正在使用System.Net; 我有以下代码:
WebClient ww = new WebClient();
ww.DownloadFileAsync(
new Uri("http://www.sinvise.net/tester/1.jpg"),
AppDomain.CurrentDomain.BaseDirectory + "\\1.jpg");
Run Code Online (Sandbox Code Playgroud)
问题是,它是不下载文件,它只是显示为0kb文件而不是下载,我不知道是什么问题,任何人都可以帮忙吗?
如何监听DownloadFileCompleted事件并检查AsyncCompletedEventArgs.Error属性事件转发到您的处理程序?
public static void DownLoadFileInBackground(string address)
{
WebClient client = new WebClient();
Uri uri = new Uri(address);
client.DownloadFileCompleted += (sender,e)=>
{
//inspect e here:
//e.Error
};
client.DownloadProgressChanged += (sender,e)=>
{
//e.ProgressPercentage
};
client.DownloadFileAsync(uri, "blabla");
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8194 次 |
最近记录: |