c# - Thread's response time is very much(not usual) -


i want download file in c# using thread in windows form app,thread works fine @ first(for 5 seconds) leaves work , not respond 10 seconds returns second , not respond using class downloading file here code:

 class downloadfile {      #region fields      static double totalsize;     double received;     int partnum;     long start, end;     string savepath;     httpwebrequest request;      stream stream;     #endregion      #region constructors     public downloadfile() { totalsize = 1; received = 0; }     public downloadfile(long s, long e, string path, httpwebrequest request, int partnumber)     {         totalsize = 1;         partnum = partnumber;         received = 0;         start = s;         request = request;         end = e;         savepath = path;      }     #endregion      #region methods     public void download()     {         int bytesread = 0;         byte[] buffer = new byte[1024];         filestream fstr = new filestream(savepath + "part_" + partnum + path.getextension(request.requesturi.tostring()), filemode.create, fileaccess.write);         httpwebresponse response;         this.request.addrange(start, end);         response = (httpwebresponse)this.request.getresponse();         stream = response.getresponsestream();         totalsize = this.end;         bytesread = stream.read(buffer, 0, buffer.length);         while (bytesread > 0)         {             received += bytesread;             fstr.write(buffer, 0, bytesread);             bytesread = stream.read(buffer, 0, buffer.length);         }         fstr.close();         stream.close();     }     public void appendfiles()     {      }     #endregion      #region properties     public long end     {         { return end; }         set { end = value; }     }      public long start     {         { return start; }         set { start = value; }     }     public double received     {         { return received; }     }     public double totalsize     {         { return totalsize; }     }     public httpwebrequest request     {         { return request; }         set { request = value; }     }      public string savepath     {         { return savepath; }         set { savepath = value; }     }     #endregion  } 

and here thread starts:

class program{ list<downloadfile> downloadlist = new list<downloadfile>();  public void downloadmethod()     {         (int = 0; < downloadlist.count; i++)         {             new thread(new threadstart(downloadlist.elementat(i).download)).start();         }      } } 

and have timer updates download form(progressbar , labels)


Popular posts from this blog