我的程序中遇到一个问题: 根据文件列表下载文件,并要加载和执行其中的DLL文件,整个过程要用进度条来显示程序运行的进度,请问大家有什么好的方法?请帮帮忙,谢谢!

解决方案 »

  1.   

    你先要知道该加载和执行其中的DLL文件的大小,再设计StatuStrip 执行时的速度,(采用TImer控件控制速度)
      

  2.   

    public static void DownFile( string URL, string Filename, ProgressBar Prog )
    {
      System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
      System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse();
      long totalBytes = myrp.ContentLength;
      Prog.Maximum = (int)totalBytes;
      System.IO.Stream st = myrp.GetResponseStream();
      System.IO.Stream so = new System.IO.FileStream(Filename, System.IO.FileMode.Create);
      long totalDownloadedByte = 0;
      byte[] by = new byte[1024];
      int osize = st.Read(by, 0, (int)by.Length);
      while (osize > 0)
      {
        totalDownloadedByte = osize + totalDownloadedByte;
        Application.DoEvents();
        so.Write(by, 0, osize);
        Prog.Value = (int)totalDownloadedByte;
        osize = st.Read(by, 0, (int)by.Length);
      }
      so.Close();
      st.Close();
    }