Program update based on C/s mode-download

Source: Internet
Author: User

Ideas:

① Check if an update is required (get the latest version number and local version number from the database (the local version number can exist in the TXT file, and some encryption and decryption operations are required))

② Download the latest version of the program from the specified directory to overwrite local files (compressed files when downloading files)

③ compressed files in-program decompression (it is possible that the client computer is not installed compression software, so only through the program itself to extract)

④ Call the main program after decompression is complete

Realize:

Download: WebClient

1 if(webclient.isbusy)//whether there is a Web request in progress2             {3 Webclient.cancelasync ();4             }5             //add an event for WebClient6Webclient.downloadprogresschanged + =NewDownloadprogresschangedeventhandler (webclient_downloadprogresschanged);7webclient.downloadfilecompleted + =NewAsynccompletedeventhandler (webclient_downloadfilecompleted);8             //Start Download9             stringPath = ExePath +@"\update.rar";TenWebclient.downloadfileasync (NewUri ( This. Txtfilepath.text), path);

1  Private voidWebclient_downloadprogresschanged (Objectsender, DownloadProgressChangedEventArgs e)2         {3 4              This. progressBar1.Value =E.progresspercentage;5              This. Lbl_pro. Text = e.progresspercentage.tostring () +"%";6              This. Lbl_detail. Text =string. Format ("downloading....,{0}/{1} (Byte)"7 , e.bytesreceived8 , e.totalbytestoreceive);9             if(E.totalbytestoreceive = =e.bytesreceived)Ten             { One                  This. Lbl_detail. Text = ("DownLoad success. Update now, wait a second! "); A             } -}

1  Private voidWebclient_downloadfilecompleted (Objectsender, AsyncCompletedEventArgs e)2         {3             if(e.cancelled)4             {5DevExpress.XtraEditors.XtraMessageBox.Show ("Download is canceled!","Error", MessageBoxButtons.OK, Messageboxicon.error, messageboxdefaultbutton.button1);6                 return;7             }8             Else9             {Ten  One                 if( This. Lbl_detail. Text = = ("DownLoad success. Update now, wait a second! ")) A                 { -Thread T =NewThread (//the method of actually updating); -Checkforillegalcrossthreadcalls =false; the T.start (); -                 } -  -             } +}

Program update based on C/s mode-download

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.