Example #1
0
 public NewDownloader(DownloadTask task)
 {
     DownloadProgress = 0;
     try
     {
         path = task.localPath;
         SHA1 = task.sha1;
         url  = task.url;
         size = task.size;
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.Message);
     }
 }
        void AddTasks()
        {
            for (int i = 0; i < DownloadThreads; i++)
            {
                if (!threads[i].IsAlive)
                {
                    if (DownloadList.Count != 0)
                    {
                        if (!uncheck)
                        {
                            DownloadTask thisTask = DownloadList.Dequeue();
                            if (!thisTask.isDownloading)
                            {
                                thisTask.isDownloading = true;
                                threads[i]             = new Thread(new ThreadStart(thisTask.SingleDownload));
                            }
                            else
                            {
                                continue;
                            }
                        }

                        else
                        {
                            DownloadTask thisTask = DownloadList.Dequeue();
                            if (!thisTask.isDownloading)
                            {
                                thisTask.isDownloading = true;
                                threads[i]             = new Thread(new ThreadStart(thisTask.SingleDownloadUncheck));
                            }
                            else
                            {
                                continue;
                            }
                        }
                        threads[i].Start();
                    }
                }
            }
        }
Example #3
0
 /// 下载文件方法
 /// 文件保存路径和文件名
 /// 返回服务器文件名
 public static void DownloadFileFromTask(DownloadTask task)
 {
     DownloadFile(task.url, task.localPath);
 }