当前位置: 首页>>代码示例>>C#>>正文


C# System.Net.WebClient.DownloadFileTaskAsync方法代码示例

本文整理汇总了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);
                }
            }        
        }
开发者ID:RParkerM,项目名称:PadMonsterInfo,代码行数:36,代码来源:Methods.cs

示例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;
			}
		}
开发者ID:kumaryu,项目名称:peercaststation,代码行数:23,代码来源:UpdaterViewModel.cs


注:本文中的System.Net.WebClient.DownloadFileTaskAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。