简体   繁体   中英

The operation has timed out

We shave this code which result in timeout when downlaoding the file programatically:

System.Net.WebClient Client = new System.Net.WebClient();
if (!File.Exists(fileName))
{
    Client.DownloadFile(downloadLink, fileName);
    HtFilesSuccessfullyDownloaded[fileName] = fileName;
    string SuccessfullyDownloadedFiles = Path.Combine(dirName, "SuccessfullyDownloadedFiles.txt");
    File.AppendAllText(SuccessfullyDownloadedFiles, Environment.NewLine + fileName);
}

It looks like when the files are large we are getting the timeout error when DownloadFile method is called. We have added the followign in web.config but it does not look like it helps:

 <httpRuntime maxRequestLength="1048576" executionTimeout="3600"
/>

Please let me know if you have any suggestions.

Have you tried using Fiddler to see what is exactly happening? It might provide you with some more clues. Frankly it could even be a problem with the Webserver, and not your code. Also HTTPWebrequest has a timeout that you can set. You could try that instead.

Fiddler
HttpWebrequest

You are downloading the file to your server and the web.config entry is applicable for the files uploaded from a client.

Check this question for the answer you need

Set timeout for webClient.DownloadFile()

Out of curiosity...What will you be showing the user when the download is in progress?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM