I'm developing a C# project to download the files from the internet.
I'll show the progresses of them while the downloads are going. And I should support the time-out property.
I've tried to use the WebClient class. There are DownloadFile() and DownloadFileAsync() functions.
- When I use DownloadFile() function, I can set the Timeout property, overriding the GetWebRequest() function. However, I can't fire the event handlers, so I can't show the progresses.
- When I use DownloadFileAsync() function, I can fire the event handlers, so I can show the progresses. But, in this case, I can't set the Timeout.
From the internet, I can find some articles about the way to set the timeout manually using threading.
However, I think that all of them are incorrect. They set the timeout during the entire download progress. But the downloading will be short or long according to the size of the file.
How can I solve this problem?