Closed bigbosschenyibo closed 5 months ago
In the name of GOD. I have same as this problem. I checked DownloadService.cs codes and i knew, this class delete uncompleted download file, before start (resume) download, then continue, but i got errors for delete, so I close my project without resume. if everybody find solution please help me. tank you viewers and bezzad. ممنونیم بهزاد. کاملش کل. عالیه
Hi everybody,
First, make sure you set false to the ClearPackageOnCompletionWithFailure
option. Because, this option tells the Downloader to clear the package and downloaded data when the download is completed with failure, but the default value is false.
Second, before downloading, keep the downloadService.Package
in a variable;
// At first, keep and store the Package file to resume
// your download from the last download position:
DownloadPackage pack = downloader.Package;
after downloading, you can stop or pause a download or the download may be completed with an error. Therefore, when you want to resume downloading at last point, just pass the package to the downloader like this:
await downloader.DownloadFileTaskAsync(pack);
Note: Sometimes a server does not support downloading in a specific range. That time, we can't resume downloads after canceling. So, the downloader starts from the beginning.
Additional info for saved your Packed, you can use json file for this:
public void SavedPacked(DownloadPackage packet, string rutaArchivo) { string json = JsonConvert.SerializeObject(packet); File.WriteAllText(rutaArchivo, json); }
public DownloadPackage ReadPacked(string rutaArchivo) { string json = File.ReadAllText(rutaArchivo); return JsonConvert.DeserializeObject<DownloadPackage>(json); }
if (File.Exists("your path .json file")) { var packed = LeerPacked("your path .json file"); Console.WriteLine("!---- OnResume ----!"); downloader.DownloadFileTaskAsync(packed); } else { Console.WriteLine("!---- OnStart ----!"); downloader.DownloadFileTaskAsync("url file to download", " your file name"); }
Use SavePacked in dDownloadProgressChanged
Considering that the file may be interrupted in downloading, I will download the file xx to xx.temp first, and if the download is successfully completed, I will convert xx.temp to xx. But if the download is interrupted, I want to be able to continue starting from the left off the next time the program starts, and I want to know if you have provided the relevant features to support my scenario? Thank you in advance for your help. Below is the code I tried for this purpose:
I was confused that the file download did not work as expected.