/// <summary> /// 获取文件下载器 /// </summary> /// <param name="onDownload">下载结束委托</param> /// <param name="listName">列表名称</param> /// <param name="fileStream">文件流</param> /// <returns>文件下载器</returns> public static Action GetDownload (Func <returnValue <listName>, bool> onDownload, listName listName, Stream fileStream) { downloader downloader = typePool <downloader> .Pop() ?? new downloader(); downloader.listName = listName; downloader.onDownload = onDownload; downloader.fileStream = fileStream; return(downloader.downloadHandle); }
private async void DownloadProgress() { List <downloader> files = new List <downloader>(); for (int i = 0; i < 10; i++) { MCDownload download = AssignedDownload(); if (download != null) { downloader fileDownloader = new downloader(); fileDownloader.BuildDownload(download.Url, download.path); fileDownloader.StartDownload(); files.Add(fileDownloader); } } if (files.Count == 0) { Progress = 100; DuckEndDownload = download.Length; return; } await Task.Factory.StartNew(() => { while (true) { int end = 0; for (int i = 0; i < files.Count; i++) { Speed += files[i].intermation.Speed; if (files[i].intermation.StatusId == -1) { error++; } if (files[i].intermation.Progress == 100) { end++; } } if (end >= files.Count) { DuckEndDownload += files.Count; Speed = 1; Progress += 100 / (double)(download.Length) * files.Count; DownloadProgress();//递归 return; } Thread.Sleep(200); } }); }