Open Gennady-G opened 8 years ago
I cancel in DownloadProgressChanged. If app hangs, it's probably a multi-threading issue.
For reference, here is my own code
private async Task DownloadVideoAsync(DownloadItem downloadInfo, DownloadItem.FileProgress fileInfo, EventHandler<DownloadCompletedEventArgs> callback) {
downloadInfo.Status = DownloadStatus.Downloading;
VideoDownloader YTD = new VideoDownloader(fileInfo.Source, fileInfo.Destination);
YTD.DownloadProgressChanged += (sender, e) => {
if (downloadInfo.IsCanceled)
e.Cancel = true;
else {
fileInfo.BytesTotal = YTD.DownloadSize;
fileInfo.BytesDownloaded = e.ProgressBytes;
downloadInfo.UpdateProgress();
}
};
// Run downloader task.
await Task.Run(() => {
try {
YTD.Execute();
} catch {
downloadInfo.Status = DownloadStatus.Failed;
}
}).ConfigureAwait(false);
}
@mysteryx93 , thank You much!
Best regards,
Gennady
Hi guys!
Im. trying to use this lib in WinForm GUI app. Works cool, the only one problem - it cannot stop :-)
BackgroundWorker control allows to set CancellationPending flag, and then manually check it in DoWork function(while processing).
By instance:
How to realize that with Your library? I was triyng to cancel in DownloadProgressChanged, but app hangs. I think it could be done only in DoWork() function.. Here is big listing what I'm trying to do: