c# - How can i download a file faster? -


i have made download program in c#. queue downloader. can see how works here: click express downloader

is there faster method download? here method use, must support resume support.

private void download(object startpoint)     {         try         {             try             {                 //int startpointint = convert.toint32(startpoint);                 int64 startpointint = convert.toint64(startpoint);                 webrequest = (httpwebrequest)webrequest.create(url);                 webrequest.addrange(startpointint);                 webrequest.credentials = credentialcache.defaultcredentials;                 webresponse = (httpwebresponse)webrequest.getresponse();                 int64 filesize = webresponse.contentlength;                 strresponse = webresponse.getresponsestream();                 if (startpointint == 0)                 {                     strlocal = new filestream(txtpath.text + "\\" + filename, filemode.create, fileaccess.write, fileshare.none);                 }                 else                 {                     strlocal = new filestream(txtpath.text + "\\" + filename, filemode.append, fileaccess.write, fileshare.none);                 }                 int bytessize = 0;                 byte[] downbuffer = new byte[4096];                 while ((bytessize = strresponse.read(downbuffer, 0, downbuffer.length)) > 0)                 {                     strlocal.write(downbuffer, 0, bytessize);                     this.invoke(new updateprogesscallback(this.updateprogress), new object[] { strlocal.length, filesize + startpointint });                      if (gopause == true)                     {                         break;                     }                 }             }             catch { }         }                 {              strresponse.close();             strlocal.close();         }     } 

you have 2 things,

  1. get faster bandwidth
  2. change block size 4096 8192 or number can hold in memory easily.

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -