I am developing a C # project to download files from the Internet.
I will show how they progress at boot time. And I have to maintain the timeout property.
I tried using the WebClient class. There are functions DownloadFile () and DownloadFileAsync ().
- When I use the DownloadFile () function, I can set the Timeout property by overriding the GetWebRequest () function. However, I cannot run event handlers, so I cannot show progress.
- When I use the DownloadFileAsync () function, I can run event handlers so that I can show the progress. But in this case, I can not set Timeout.
From the Internet, I can find several articles on how to manually set a timeout using streams.
However, I believe that they are all wrong. They set a timeout during the entire boot process. But the download will be short or long depending on the file size.
How can I solve this problem?
source share