本文整理汇总了C#中System.Net.WebClient.DownloadFileTaskAsync方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.WebClient.DownloadFileTaskAsync方法的具体用法?C# System.Net.WebClient.DownloadFileTaskAsync怎么用?C# System.Net.WebClient.DownloadFileTaskAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebClient
的用法示例。
在下文中一共展示了System.Net.WebClient.DownloadFileTaskAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: downloadFileAsyncQueue
private async static Task downloadFileAsyncQueue(string remoteUrl, string localUrl)
{
if (downloads == null) downloads = new List<Tuple<string, string>>();
if (!downloads.Contains(new Tuple<string, string>(remoteUrl, localUrl)))
{
downloads.Add(new Tuple<string, string>(remoteUrl, localUrl));
while (downloading)
{
await Task.Delay(100);
}
downloading = true;
//Debug.WriteLine("begin downloading..." + localUrl);
try
{
using (System.Net.WebClient webClient = new System.Net.WebClient())
{
await webClient.DownloadFileTaskAsync(new Uri(remoteUrl), localUrl);
}
}
catch(Exception e)
{
Debug.WriteLine(e);
downloading = false;
}
//Debug.WriteLine("done downloading");
downloading = false;
}
else
{
while(downloads.Count > 0)
{
await Task.Delay(100);
}
}
}
示例2: DoDownload
public async System.Threading.Tasks.Task DoDownload()
{
var client = new System.Net.WebClient();
client.DownloadProgressChanged += (sender, args) => {
this.Progress = args.ProgressPercentage/100.0;
};
cancelSource.Token.Register(() => {
client.CancelAsync();
}, true);
this.State = UpdateActionState.Downloading;
try {
downloadPath = System.IO.Path.Combine(
Shell.GetKnownFolder(Shell.KnownFolder.Downloads),
System.IO.Path.GetFileName(SelectedEnclosure.Url.AbsolutePath));
await client.DownloadFileTaskAsync(
selectedEnclosure.Url.ToString(),
downloadPath);
this.State = UpdateActionState.Downloaded;
}
catch (System.Net.WebException) {
this.State = UpdateActionState.Aborted;
}
}