This software uses WebClient. downloadfileasync to download network data. A simple program.
Source program:
Using system; using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. LINQ; using system. text; using system. windows. forms; using system. net; using system. net. sockets; using system. io; namespace flydown {public partial class form1: FORM {timer = new timer (); long timecount = 0; Public form1 () {initializecomponent (); timer. enabled = false; timer. interval = 1000;} private void form1_load (Object sender, eventargs e) {} private void button#click (Object sender, eventargs e) {timer. enabled = true; timer. tick + = new eventhandler (timer_tick); timespan ts1 = new timespan (datetime. now. ticks); Using (WebClient WC = new WebClient () {If (textbox1.text. trim () = "") MessageBox. show ("Enter the download path"); else if (textbox2.text. trim () = "") MessageBox. show ("Enter the file storage name"); else {try {WC. proxy = NULL; Uri address = new uri (textbox1.text. tostring (); // call the downloadfile method to download the file // WC. downloadfile (textbox1.text. tostring (), textbox2.text. tostring (); // call downloadfileasync to asynchronously download the WC file. downloadfileasync (address, textbox2.text. tostring (); WC. downloadprogresschanged + = new downloadprogresschangedeventhandler (wc_downloadprogresschanged); // The download completed RESPONSE event WC. downloadfilecompleted + = new asynccompletedeventhandler (wc_downloadfilecompleted); // If (file. exists (textbox2. text. tostring () // {// timespan ts2 = new timespan (datetime. now. ticks); // timespan Ts = ts2.subtract (ts1 ). duration (); // MessageBox. show ("File Download complete. download time: "+ ts. hours. tostring () + "Hour" + // ts. minutes. tostring () + "Minute" + ts. seconds. tostring () + "seconds"); //} catch (exception ex) {MessageBox. show (ex. message) ;}}} private void timer_tick (Object o, eventargs e) {timecount ++ ;}// indicates that the download is complete. The private void wc_downloadfilecompleted (Object sender, asynccompletedeventargs e) {MessageBox. show ("Download complete, download time:" + timecount + "seconds");} // define the progress bar RESPONSE event private void wc_downloadprogresschanged (Object sender, downloadprogresschangedeventargs e) {progressbar1.value = E. progresspercentage;} private void button2_click (Object sender, eventargs e) {system. diagnostics. process. start (textbox2.text. tostring ();} private void button3_click (Object sender, eventargs e) {// MessageBox. show (application. executablepath + "+" + directory. getcurrentdirectory () + "+" + application. startuppath); system. diagnostics. process. start (application. startuppath );}}}