-
-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DownloadPackge.Storage initialized twice when library begins from local DownloadPackage json file #166
Comments
if (File.Exists(processFile)) |
@liuhj1018 When you check the null condition for storage, don't update storage when it was used before. So, when I want to use the Downloader object again to download another URL, I get it wrong because I use an older storage stream and override the old data with new data. |
Do you stop the Downloader process with the |
No, I don't call the stop method. I just simulate the program or the computer has benn suddenly shut down. This is not normal but happen. |
I want to write the Package to the local file using "var packageJson = JsonConvert.SerializeObject(package);". But Where I put the sentence? OnDownloadProgressChanged or OnChunkDownloadProgressChanged method? |
In the case of sudden shutdowns (like a power failure or unexpected program termination), you’ll want to back up the When to Serialize and Backup the PackageYou’re right to consider the performance impact of serializing the package on every Steps to Take:
Here's a rough idea of how debouncing could be implemented: private DateTime _lastSerializedTime = DateTime.MinValue;
private readonly TimeSpan _debounceInterval = TimeSpan.FromSeconds(5);
void OnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
if (DateTime.Now - _lastSerializedTime > _debounceInterval)
{
var packageJson = JsonConvert.SerializeObject(package);
File.WriteAllText("packageBackup.json", packageJson);
_lastSerializedTime = DateTime.Now;
}
} This way, you can ensure the package is backed up regularly without overwhelming the system. I haven’t fully tested this particular scenario, but I believe this approach should work for your needs. Let me know if you need any more help with this! |
I don't Undrestand the right issue. According to the previews answer you must handle race conditions by debouncing and locking objects to prevent write conflict issues. please explain more about what happened. |
1.packageBackup.json write conflict. I had used locking object method first, but its efficiency was low. So now I use File.WriteAllTextAsync method. |
Hi @bezzad , I think the cause of this problem is that the |
Sorry for the delayed response; I've been quite busy these past few weeks. |
Thank you for bringing this issue to our attention! We've made several updates and improvements to the Downloader package. Please test the newly released v3.3.0 and let us know if you're still encountering the issue. |
I download a large file. I put the downloadpackage json file to the disk. When I reboot the progress and resume from the json file, a error shows the datafile is in use. I find line 25 and line 87 same in the ConcurrentStream.cs and I modify the DownloadPackage.cs. The datafile can be downloaded correctly.
Is it a bug? or I use in a wrong way?
Look forward for reply!
The text was updated successfully, but these errors were encountered: