473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Download file with maximum timeout

Hi

My question is:

What is the best way to download file giving it maximum timeout ( for
example 30 minutes ). After this time the operation should be
terminated ( maybe exception ? ). I was thinking about simplest
possible solution WebClient class but don't know if it is possible to
implement timeout...

Regards
Piotr Kolodziej

Nov 10 '07 #1
3 6214
Piotrekk,

You can derive a class from the WebClient class and provide a public
method/property which will call the protected GetWebRequest method and then
set the Timeout property on that.

Or, you could just use the HttpWebRequest/HttpWebResponse (assuming you
are using HTTP, you can do it for any class that derives from WebRequest)
and set the Timeout property.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Piotrekk" <Pi*************@gmail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
Hi

My question is:

What is the best way to download file giving it maximum timeout ( for
example 30 minutes ). After this time the operation should be
terminated ( maybe exception ? ). I was thinking about simplest
possible solution WebClient class but don't know if it is possible to
implement timeout...

Regards
Piotr Kolodziej
Nov 10 '07 #2
Thank you. I will try with your first advice ;-) Seems good enought to
me.

Nov 11 '07 #3
I did as you said:

public class MyWebClient : WebClient
{
public void MyDownload(Uri u)
{
Stream s = null;
FileStream fs = null;

try
{
WebRequest request = GetWebRequest(u);
WebResponse ws = request.GetResponse();

s = ws.GetResponseStream();
fs = new FileStream("ddd.avi", FileMode.Create);

byte[] buffer = new byte[32768];
int i;

while ((i = s.Read(buffer, 0, buffer.Length)) != 0)
{
fs.Write(buffer, 0, i);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
if (fs != null)
{
fs.Close();
}

if (s != null)
{
s.Close();
}
}
}
}

However i can see that it's not what I expected. I've observed that
Timeout affects only WebResponse ws =
request.GetResponse() line.
When i read from response Timeout doesn't change anything anymore.
It's not counting 0-timeout.

Nov 11 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
7
by: Joe | last post by:
I have an upload file operation in the web application. UploadForm.asp is the form, and UploadAction.asp is the form processing. //UploadForm.asp <FORM NAME="InputForm"...
15
by: dee | last post by:
Hi, What is the maximum number of minutes for Session timeout that I can specify in web.config? Thanks. Dee
2
by: Raj Dhrolia | last post by:
Hi, Can anyone suggest me best way to upload large files (>100-500MB) to my ASP.NET web application (IIS 6.0, Win 2K3). The problem we see with conventional method is that the session times out,...
0
by: bonita | last post by:
If I add the code for user to download the file (e.g. if(File.Exists(FILE_NAME)){......}), the ASP.NET will give the following timeout error: Timeout expired. The timeout period elapsed prior to...
1
by: a.r.austin | last post by:
Hello, I am trying to download a few files one after another from a remote server. Problem is that I don't know how to, or if I am able at all, set a time out for download. I don't want to time...
4
by: bienwell | last post by:
Hi all, I developed an web page in ASP.NET to upload file into the server. In the Web.config file, I declared <httpRuntime executionTimeout="1200" maxRequestLength="400000" /> The MAX...
10
by: =?Utf-8?B?SnVhbg==?= | last post by:
Hi! I want to use ASP to download big files using ADODB.STREAM. It works very fine with files smaller than 80 MB. On the Webserver I can see that memory allocation and the process w3wp is...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.