Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2084
  • Last Modified:

Set timeout for webClient.DownloadFile()

I am trying to download a .pdf file from an URL and their webserver is very, very slow which is causing a timeout in my WebClient object.

Here is my code:

WebClient webClient = new WebClient();
webClient.DownloadFile(downloadUrl, downloadFile);

Is there a way to set an definite timeout on this object?
Or if not can anyone help me with an example on an alternate way to do this?

The URL works fine in a browser - it just takes about 3 minutes to show.

example with step by step will be appriciated.

Thanks,
Vego
0
vegoreddy
Asked:
vegoreddy
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
use WebClient.DownloadFileAsync instead of WebClient.DownloadFile, and use your own timer, so when the timeout you decide is reached, you can call CancelAsync().
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now