如何写下载器(急)

解决方案 »

  1.   

    单线程下载
            /// <summary>
            /// 下载文件
            /// </summary>
            private void StartDownLoad()
            {
                string url = string.Empty;
                string fileName = string.Empty;
                int n = 0;
                string path = string.Empty;
                url = txtURI.Text;
                n = url.LastIndexOf('/');
                fileName = url.Substring(n + 1);
                path = txtbLocal.Text + "\\" + fileName;
                    try
                    {
                        WebRequest request = WebRequest.Create(url);
                    }
                    catch (WebException ex)
                    {
                        MessageBox.Show(ex.Message, "Error");
                    }                try
                    {
                        WebClient client = new WebClient();
                        stBar.Text = "开始下载文件...";
                        client.DownloadFile(url, path);
                        stBar.Text = "下载完毕,文件已经保存到" + path.ToString();
                    }
                    catch (WebException ex)
                    {
                        MessageBox.Show(ex.Message, "Error");
                        stBar.Text = string.Empty;
                    }
                    finally
                    {
                        btnDownLoad.Enabled = true;
                    }
            }        private void btnDownLoad_Click_1(object sender, EventArgs e)
            {
               //开启线程,以改善用户体验.
               Thread th=new Thread(new ThreadStart(StartDownLoad));
               //th.Name="New DownLoad";
               th.Start();
            }
      

  2.   

    多线程:
    http://www.51aspx.com/CV/MultiThreadDownLoadFile/