PC Review


Reply
Thread Tools Rate Thread

How do I reliably download and save files on CE4.1

 
 
Steve
Guest
Posts: n/a
 
      7th Jul 2003
Hi,

I'm having problems downloading and saving files from the Internet.
When I run the following code multiple times it grinds to a halt on CE4.1
The first time I call it, it works ok, then it gets really slow, and if I
leave it running it takes minutes to return.
However the same exe running on the desktop is fine, and will download all
files fine.

I have a Nexio S160 connected using Wi-Fi,

Any ideas ?

Cheers,
Steve.

int download_file(string webname,string fname)
{
try
{
Stream str;
System.Net.HttpWebRequest wr;
System.Net.HttpWebResponse ws;
FileStream fstr;
wr=(System.Net.HttpWebRequest)System.Net.WebRequest.Create(webname);
ws=(System.Net.HttpWebResponse)wr.GetResponse();
str=ws.GetResponseStream();
BinaryReader reader=new BinaryReader(str,Encoding.UTF8);
int bytesToRead = (int) inBuf.Length;
int bytesRead = 0;
int n;
while(bytesToRead>0)
{
n=reader.Read(inBuf,0,262144*4);
if(n==0)break;
bytesRead+=n;
bytesToRead-=n;
}
str.Close();
ws.Close();
reader.Close();
fstr = new FileStream(fname, FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(inBuf, 0, bytesRead);
fstr.Flush();
fstr.Close();
}
catch
{
return(1);
}
return(0);
}


 
Reply With Quote
 
 
 
 
Jon Skeet
Guest
Posts: n/a
 
      7th Jul 2003
Steve <(E-Mail Removed)> wrote:
> I'm having problems downloading and saving files from the Internet.
> When I run the following code multiple times it grinds to a halt on CE4.1
> The first time I call it, it works ok, then it gets really slow, and if I
> leave it running it takes minutes to return.
> However the same exe running on the desktop is fine, and will download all
> files fine.


I don't know why you're having problems, but your reading code is
definitely flawed. You're reading to the start of your buffer every
time, rather than from the position you'd got to. Your call:

n=reader.Read(inBuf,0,262144*4);

should be

n=reader.Read(inBuf,bytesRead,bytesToRead);

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      8th Jul 2003
Oops,
Just noticed that I posted the wrong reader code, like I said it did run
fine on the desktop, but I've been trying all sorts to try and get it to
work on CE4.1 .

I Just noticed something weird however. Sometimes when I run it, it works as
expected taking about a second per request and other times just sits there
waiting.

"Jon Skeet" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Steve <(E-Mail Removed)> wrote:
> > I'm having problems downloading and saving files from the Internet.
> > When I run the following code multiple times it grinds to a halt on

CE4.1
> > The first time I call it, it works ok, then it gets really slow, and if

I
> > leave it running it takes minutes to return.
> > However the same exe running on the desktop is fine, and will download

all
> > files fine.

>
> I don't know why you're having problems, but your reading code is
> definitely flawed. You're reading to the start of your buffer every
> time, rather than from the position you'd got to. Your call:
>
> n=reader.Read(inBuf,0,262144*4);
>
> should be
>
> n=reader.Read(inBuf,bytesRead,bytesToRead);
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet/
> If replying to the group, please do not mail me too



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Download files won't save =?Utf-8?B?VGVycnkgTA==?= Spyware Application Compatibility 29 16th Oct 2009 06:43 PM
RE: Download files won't save =?Utf-8?B?QnVsbGV0Rm9zcw==?= Spyware Application Compatibility 1 27th Feb 2006 04:30 PM
linked music files not working reliably on another computer =?Utf-8?B?UGV0ZXJL?= Microsoft Powerpoint 6 6th Feb 2006 07:16 AM
download to be able to save files as CSV in Excel? =?Utf-8?B?QnJpYW5I?= Microsoft Excel Misc 1 22nd Dec 2004 04:11 AM
Can't download/save files from internet any more - help! Dirk Taylor Windows XP New Users 3 12th Nov 2003 08:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:34 PM.