Download network data using WebClient. downloadfileasync-simple download software

Source: Internet
Author: User

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 );}}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.