I remember that when I just used it, WebClient did look very simple, but realized, the small file is overloaded. The big file should have been downloaded. Later, I found it, use WebRequest combined with WebResponse to achieve progress prompt. , Download the file .. Here is the code .. is extracted from a software. Just take the key part of the description ... ===================== ======================================================= iv (Downloading == false) // If no file is being downloaded {TempDown = CurrentFileName; if (CurrentFileName == "") {TempDown = b;} WhichDown = 1; System.Threading.Thread ApcThread2 = new System.Threading.Thread (new System .Threading.ThreadStart (DownFile); apcthread2.start ();} else {messagebox.show ("Sorry, the file is currently being downloaded.", "Prompt", messageboxbuttons.ok, messageboxicon.information;} #### ############## Probably, if the current no file is downloading, start a new thread .... Download the file .. The following is the code of the downfile function .... Simple There is not a comment. ============================================= ============================================= // download block ############ ######################################################################################################################################################################################################################################################################################################## ###################################################################### "") {If (downloading == false) // If there is no file download {long fb; THIS.APC_STATUS_1.TEXT = "is connected to" Tempdown;
Downloading = true; try {// ==== try URL effectiveness, download and initialization interface WebRequest myre = WebRequest.Create (TempDown); WebResponse mwrite = myre.GetResponse (); fb = mwrite.ContentLength; this.apc_status_1. Text = "Connection is successful .. Start download."; PBAR.Value = 0; PBAR.Maximum = (int) FB; PBAR.Visible = true; this.apclist.height = 156; // ==== Start download WebClient wc = new WebClient (); SaveFileDialog sf = new SaveFileDialog (); sf.Title = "Please choose file storage position"; filename = CurrentFileName; sf.FileName = filename.Substring (filename.LastIndexOf ( "/") 1, filename.length-filename.lastindexof ("/") - 1); sf.showdialog (this); filename = sf.FileName; if (filename! = ") {Stream srm = wc.openread (Tempdown); StreamReader Srmer = New StreamReader (SRM); Byte [] mbyte = new byte [fb]; int allbete = (int) mbyte.length; int startByte = 0; while (fb> 0) // ####### ######### 读 读 文件, display progress ..... {Application.doevents (); int m = srm.read (Mbyte, StartByte, Allbyte ); If (m == 0) {Break;} StartByte = m; allbyte- = m; PBAR.Value = m; int A1 = (int) startbyte / 1024; int A2 = (int) FB / 1024; this. APC_STATUS_1.TEXT = "Connection is successful .. Start downloading .." a1.tostring () "kb"; // startbyte "/" fb.toString ();} FileStream Fs = New FileStream (FileName, FileMode.Openorcreate); fs.write (mbyte, 0, mbyte.length); fs.flush (); srm.close (); srmer.close ();