Here's a simple DownloadFileAsync class that allows resuming and also returns a few extra properties, like download speed, download time and remaining time. You can specify the update frequency (no delay, every 500ms or every second), so the ProgressChanged event doesn't fire continuously and hog CPU when updating controls.
The added example also shows you how to create an ownerdrawn ListView, so you can draw a custom progressbar, in order to show the download progress.
This version only supports Http downloads, because that's what most people use DownloadFileAsync for.
The DownloadFileAsyncExtended, HttpWebRequestState, FileDownloadProgressChangedEventArgs and FileDownloadCompletedEventArgs classes have been added to a single file for convenience. You might want to put each class in its own file.
I'm sure there are a few things that can be improved, so comments are welcome.
I had to remove all executables from the project before posting it here. You might get a warning "Could not find type 'SampleProject.ListViewExtended'". In that case, Build the sample project first and restart the project.
Last edited by Chris001; Jan 20th, 2012 at 12:34 AM.
Re: WebClient DownloadFileAsync with resume support
Thanks , Very Nice but something is missing there .. when we close the application with resuming half download of any file .. in next attempt it is not there .. please add after resuming if application is closed in next attempt we should be promoted to continue previous resumed download..
Re: WebClient DownloadFileAsync with resume support
Originally Posted by janu
Thanks , Very Nice but something is missing there .. when we close the application with resuming half download of any file .. in next attempt it is not there .. please add after resuming if application is closed in next attempt we should be promoted to continue previous resumed download..
Of course it's not there; the program doesn't know you want to keep it. Granted, you can do that [there are Downloading Applications out there that do such a thing], it just requires a bit more code.
Re: WebClient DownloadFileAsync with resume support
Originally Posted by janu
Thanks , Very Nice but something is missing there .. when we close the application with resuming half download of any file .. in next attempt it is not there .. please add after resuming if application is closed in next attempt we should be promoted to continue previous resumed download..
Sorry, but I'm not going to add that. It seems you have misunderstood what this code is about. The normal WebClient class rejects the Range header, preventing you from downloading only a part of the file, thus resuming. This class allows you to download files, just like you would do with the normal WebClient class, but this one supports resuming.
The included project is just a Sample Project, that simply shows you how to use the download class and nothing more. Remembering partially finished downloads and other features is something you'll have to add yourself... you are the programmer
Re: WebClient DownloadFileAsync with resume support
Thanks for this. I learned a LOT from it. I program in C# and was using WebClient to transfer files between PCs around the country in our network. I found you by Googling about doing resumes.
- You got me to switch to HttpWebRequests
- I converted your DownloadFileAsyncExtended.vb to a C# version using http://www.developerfusion.com/tools.../vb-to-csharp/ (not bad!) and some tweaks
- The passing around of ListViewItems sure made my job easier
- I also like storing the DownloadFileAsyncExtended objects in the ListViewItem Tags. I often have a problem figuring out how to trace my steps and find out where I'm coming from
- Hate to admit it, but I'd never used SmallImageList before. Very cool.
- This is a really great foundation for extending it to do resumes after restarting. My basic setup on this project is to try to keep files at remote sites in sync with "local" files
Just wanted to thank you for sharing your work. I don't take the time to do that enough in this generous online community of programmers we have on the Internet.
Re: WebClient DownloadFileAsync with resume support
what should I do For make it Resume exist file !?
I`m Trying to make it save list items when Close and resume if Open it again
I`m Sticking with this Problem !
I Give it same File name and I Active ResumeAsync
Code:
If _ResumeAsync Or AResumeAsync Then
'If _ResumeAsync Then
Dim FileInfo As New FileInfo(LocalFilePath)
If FileInfo.Exists Then
Request.AddRange(FileInfo.Length)
End If
End If
its rewrite file and start from beginning !
Thank for advice
Re: WebClient DownloadFileAsync with resume support
I`m Trying to Complete This Project
I Active [ _CancelAsync = True ] For Stop rewrite uncompleted file
and Save&Load ListViewEx.Items Info
Please Post Your opinion For Help Complete it
Thank You!