'How can I download a file using WebClient in C# with firing the eventhandlers and supporting the timeout property?

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?



Solution 1:[1]

try to show this

http://www.codeproject.com/Articles/35954/C-NET-Background-File-Downloader

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alessio Koci