Previously written in the Baidu document, transferred here
Software:
Code Download:
http://twzy.ys168.com/ in the code download folder
//Code:usingSystem;usingSystem.ComponentModel;usingSystem.Net;usingSystem.Threading;usingSystem.Windows.Forms;namespacedownfile{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } stringNetPath ="Http://wlkt.zufe.edu.cn/Skyclass/C91/Courseware/Bbs/080717071122.mp3";//files that need to be downloaded stringFilePath ="d:\\just One last Dance.mp3";//path to File save Delegate voidDeldownfilehandler (intTotalnum,intNumintproc);//used to indicate file information (file size, current download quantity, percentage of current download) Delegate voidDelcomdownfilehandler (BOOLiscompleted);//after the file download is completeWebClient WC=NewWebClient (); Private voidButton1_Click (Objectsender, EventArgs e) {WC. DownloadProgressChanged+=NewDownloadprogresschangedeventhandler (wc_downloadprogresschanged); Wc. Downloadfilecompleted+=NewAsynccompletedeventhandler (wc_downloadfilecompleted); progressBar1.Value=0; Label1. Text=""; Button2. Enabled=true; Button1. Enabled=false; //start with ThreadThread td =NewThread (NewThreadStart (loadFile)); Td. IsBackground=true; Td. Start (); } //Thread Start Private voidLoadFile () {if(WC.) IsBusy) {WC. CancelAsync (); } WC. DownloadFileAsync (NewUri (NetPath), FilePath); } //events that are triggered during the update (controls cannot be manipulated directly in the thread and therefore executed with a delegate) voidWc_downloadprogresschanged (Objectsender, DownloadProgressChangedEventArgs e) { This. Invoke (NewDeldownfilehandler (Processshow),New Object[] { (int) E.totalbytestoreceive, (int) e.bytesreceived, e.progresspercentage}); } //delegate Execution (progress bar and character id) Private voidProcessshow (intTotalnum,intNumintproc) {Progressbar1.maximum=Totalnum; progressBar1.Value=num; Label1. Text="currently downloading:"+ (num/(1024x768)). ToString () +"kb/"+ (Totalnum/1024x768). ToString () +"KB"+ Proc. ToString () +"%"; } //events that are triggered after the update is completed voidWc_downloadfilecompleted (Objectsender, AsyncCompletedEventArgs e) { if(e.cancelled) This. Invoke (NewDelcomdownfilehandler (Comdownfile),New Object[] {false }); Else This. Invoke (NewDelcomdownfilehandler (Comdownfile),New Object[] {true }); } Private voidComdownfile (BOOLiscompleted) { if(iscompleted) Label1. Text="Download Complete"; ElseLabel1. Text="Download Cancel"; progressBar1.Value=0; Button1. Enabled=true; Button2. Enabled=false; } //after clicking Cancel Private voidButton2_Click (Objectsender, EventArgs e) {WC. CancelAsync (); Wc. Dispose (); } }}
The file path in the code has been invalidated, please modify it yourself
C # implements the download function, which can be used for automatic software update