/*==Method-Download==*/ private static void StartDownload() { /*==Kiểm tra tồn tại tệp tin==*/ if (File.Exists(DestPath.Trim() + ".downloading")) //tồn tại { File.Delete(DestPath.Trim() + ".downloading"); //Xoá tệp tin } /*==Set-Link-Download==*/ downloader = new MultiThreadedWebDownloader(LinkDownload) { DownloadPath = DestPath.Trim() + ".downloading" }; /*==Khai báo sự kiện xử lý download==*/ downloader.DownloadCompleted += DownloadCompleted; downloader.DownloadProgressChanged += DownloadProgressChanged; downloader.StatusChanged += StatusChanged; downloader.BeginDownload();//Bắt đầu tải tệp tin }
private void BtnDownload_Click(object sender, EventArgs e) { /*==Check whether the file exists==*/ if (File.Exists(tbPath.Text.Trim())) { string message = "Tệp tin này đã tồn tại" + "Bạn có muốn xoá tệp tin này không" + "Nếu bạn không muốn xoá thì vui lòng thay đổi đường dẫn"; var result = MessageBox.Show( message, "Tệp tin đã tồn tại " + tbPath.Text.Trim(), MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { File.Delete(tbPath.Text.Trim()); } else { return; } } if (File.Exists(tbPath.Text.Trim() + ".tmp")) { File.Delete(tbPath.Text.Trim() + ".tmp"); } /*--Set-Link-Download--*/ downloader = new MultiThreadedWebDownloader(tbURL.Text) { /*--Set-Path-Download--*/ DownloadPath = tbPath.Text.Trim() + ".tmp" }; /*==Register the events of HttpDownloadClient.==*/ downloader.DownloadCompleted += DownloadCompleted; downloader.DownloadProgressChanged += DownloadProgressChanged; downloader.StatusChanged += StatusChanged; /*--Set-Path-BeginDownload--*/ downloader.BeginDownload(); }
private static void DownloadFile(string Uri) { /*==Check whether the file exists==*/ if (File.Exists(DestPath.Trim())) { File.Delete(DestPath.Trim()); } if (File.Exists(DestPath.Trim() + ".tmp")) { File.Delete(DestPath.Trim() + ".tmp"); } /*--Set-Link-Download--*/ downloader = new MultiThreadedWebDownloader(Uri) { /*--Set-Path-Download--*/ DownloadPath = DestPath.Trim() + ".tmp" }; /*==Register the events of HttpDownloadClient.==*/ downloader.DownloadCompleted += DownloadCompleted; downloader.DownloadProgressChanged += DownloadProgressChanged; downloader.StatusChanged += StatusChanged; if (InputKey == "S") { /*--Set-Path-BeginDownload--*/ downloader.BeginDownload(); } else if (InputKey == "P") { downloader.Pause(); Console.ReadLine(); } else { downloader.Resume(); Console.ReadLine(); } }