Exemplo n.º 1
0
        public void hbfile()
        {
                       while (true)//等待
            {
                           {
                       hb = true;

                                 for (int i = 0; i < thread; i++)
                    {
                                     {
                                          if (threadw[i] == false)//有未结束线程,等待
                            {
                                              {
                                         hb = false;
                                         Thread.Sleep(100);

                                                   break;
                                       
                                }
                            }
                              
                        }
                    }
                      if(hb == true)//所有线程均已结束,停止等待,
                                 {
                        //
                            break;

                          
                    }
                     
                }
            }
              FileStream fs;//开始合并
             FileStream  fstemp;
              int        readfile;
              byte[]     bytes = new byte[512];
                         fs    = new FileStream(path + true_filename + "." + filetype, System.IO.FileMode.Create);

                        for (int k = 0; k < thread; k++)
            {
                            {
                       fstemp = new FileStream(filenamew[k], System.IO.FileMode.Open);

                                 while (true)
                    {
                                     {
                                readfile = fstemp.Read(bytes, 0, 512);

                                          if (readfile > 0)
                            {
                                              {
                                         fs.Write(bytes, 0, readfile);

                                       
                                }
                            }
                                          else
                            {
                                              {
                                         break;

                                       
                                }
                            }
                              
                        }
                    }
                       fstemp.Close();

                     
                }
            }
            for (int i = 0; i < thread; i++)
            {
                File.Delete(filenamew[i]);
            }
            File.Delete(setfilename);
              fs.Close();

            for (int j = 0; j < thread; j++)
            {
                threadk[j].Abort();
            }
            testspeed.Abort();
            TimeSpan tp = new TimeSpan();
                     tp = DateTime.Now - dt;

            TotalDownLoadTime = Convert.ToDouble(tp.TotalSeconds);
              //textBox1.Text =dt.ToString ();//结束时间
                DownLoadsize = 0;

            DownLoadtotal = 0;
              Console.WriteLine("接收完毕!!!" + TotalDownLoadTime.ToString() + "s");

            his = new Writehistory(this);
            his.AddHistory();
            MessageBox.Show("下载完成");
            downornot = false;
            hbth.Abort();
        }
Exemplo n.º 2
0
        public void hbfile()
        {
            while (true)//等待
                       {
                         hb=true;
                         for (int i=0;i<thread;i++)
                         {
                          if (threadw[i]==false)//有未结束线程,等待
                          {
                           hb=false;
                           Thread.Sleep (100);
                           break;
                  }
                         }
                 if (hb==true)//所有线程均已结束,停止等待,
                         {
                 //
                          break;
                 }
                        }
                        FileStream fs;//开始合并
                FileStream fstemp;
                        int readfile;
                        byte[] bytes=new byte[512];
                        fs=new FileStream (path+true_filename+"."+filetype,System.IO.FileMode.Create);
                        for (int k=0;k<thread;k++)
                        {
                         fstemp=new FileStream (filenamew[k],System.IO.FileMode .Open);
                         while (true)
                         {
                          readfile=fstemp.Read (bytes,0,512);
                          if (readfile>0)
                          {
                           fs.Write (bytes,0,readfile);

                          }
                          else
                          {
                           break;
                          }
                         }
                         fstemp.Close ();
                }
            for (int i=0;i<thread;i++)
            {
                File.Delete(filenamew[i]);
            }
            File.Delete(setfilename);
                       fs.Close ();

            for (int j = 0; j < thread; j++)
            {
                threadk[j].Abort();
            }
            testspeed.Abort();
            TimeSpan tp = new TimeSpan();
                       tp=DateTime.Now-dt;
            TotalDownLoadTime = Convert.ToDouble(tp.TotalSeconds);
                        //textBox1.Text =dt.ToString ();//结束时间
            DownLoadsize = 0;
            DownLoadtotal = 0;
                        Console.WriteLine("接收完毕!!!"+TotalDownLoadTime.ToString()+"s");
            his = new Writehistory(this);
            his.AddHistory();
            MessageBox.Show("下载完成");
            downornot = false;
            hbth.Abort();
        }