Pause and resume WPF download

Hello, I am working on a WPF platform oriented to the .NET framework 4.5.2. I am writing a bootloader for my application. Here is the code:

private void Download(Dictionary<int, FileAndLinkClass> MyLinks) { ApplicationDownloadThread = new Thread(() => { foreach (KeyValuePair<int, FileAndLinkClass> item in MyLinks) { fileNo++; WebClient myWebClient = new WebClient(); myWebClient.DownloadProgressChanged += MyWebClient_DownloadProgressChanged; myWebClient.DownloadFileCompleted += MyWebClient_DownloadFileCompleted; // Download the Web resource and save it into the current filesystem folder. string downloadedFileAdress = System.IO.Path.Combine(fileLocation, $"{item.Value.FileName}"); myWebClient.DownloadFileAsync(new Uri(item.Value.Link), downloadedFileAdress); while (myWebClient.IsBusy) { } } }); ApplicationDownloadThread.IsBackground = false; ApplicationDownloadThread.Start(); //UnZipAndCreateUpdatePackage(MyLinks); } 

Now I want the button to pause the download, and with the other button, click the "Download" button to resume the download. I tried working with the .set() property of the AutoReset event and the .Reset() tag, but that didn't work. I need help. My button code:

  private AutoResetEvent waitHandle = new AutoResetEvent(true); private void StartDownloadBtn_Click(object sender, RoutedEventArgs e) { waitHandle.Set(); } private void StopDownloadBtn_Click(object sender, RoutedEventArgs e) { waitHandle.Reset(); } 

I also tried this link. How to pause / pause a stream and then continue? . Nothing happens

I also went through Adding a pause and continuing to work in my bootloader , but I was not able to include the solution in my code above, as I am also updating the boot process in the user interface.

+6
source share
1 answer

Well, I did a little more digging, apparently, if you add a pause and continue working in my loader, it is not clear, since it uses byte stream data in the class, maybe you can check the link below, it also provides VS solution for WPF for Download .zip file extensions with pause / resume / stop options. Please let me know if you need further assistance.


Link to CodeProject article: C # .NET File Downloader

+1
source

All Articles