Self-written progress bar

Source: Internet
Author: User
Tags filetime

namespacedemo{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        stringAllfile =string.        Empty; Servicereference1.uploadfilesoapclient Soap=Newservicereference1.uploadfilesoapclient (); Private voidButton1_Click (Objectsender, EventArgs e) {Allfile=""; stringFtpfile = soap. Getallfilename ();//get the JSON returned by the server, get all the file names, and the file modification time            intAllfilelength =0; varJSON = Newtonsoft.Json.Linq.JArray.Parse (ftpfile);//working with JSON            varListfilename = json. Select (j = j["FileName"]). ToList ();//get a list of server file names            varFilelength = json. Select (j = j["Filelength"]). ToList ();//Get server File bytes            varFileTime = json. Select (j = j["FileTime"]). ToList ();//Get server file modification time             for(inti =0; i < Filelength.count; i++)            {                if(! System.IO.File.Exists (Path.GetFullPath (".\\") +"uponload\\"+Listfilename[i])) {Allfile+ = Listfilename[i] +",";//record file names that do not existAllfilelength + = Convert.ToInt32 (Filelength[i]);//record file size that does not exist                }                Else{FileInfo FileInfo=NewFileInfo (Path.GetFullPath (".\\") +"uponload\\"+Listfilename[i]); if(FileInfo.LastWriteTime.ToString ("YYYYMMDDHHMMSS") !=Filetime[i]. ToString ()) {Allfile+ = Listfilename[i] +",";//record file names that do not existAllfilelength + = Convert.ToInt32 (Filelength[i]);//record file size that does not exist                    }                }            }            //no update if no record count exists            if(Allfile.length >0) {Allfile= Allfile.substring (0, Allfile.length-1); MessageBox.Show ("files that need to be updated there are altogether"+ Allfile.split (','). Count () +"A total size of:"+ (Allfilelength/1024x768) +"KB"); Progressbar1.maximum= Allfile.split (',').                Count (); Thread T=NewThread (NewThreadStart (getbasestringtofile));            T.start (); }            Else{MessageBox.Show ("No update required"); }                    }        Private Delegate voidSetPoint (intpot); #regionUpdate progress bar/// <summary>        ///Update progress bar/// </summary>        /// <param name= "IPOs" ></param>        Private voidSettextmessage (intIPOs) {            if( This. invokerequired) {setpoint SetPos=Newsetpoint (settextmessage);  This. Invoke (SetPos,New Object[] {ipos}); }            Else            {                 This. Label1. Text = IPOs. ToString () +"/"+allfile.split (',').                Count ();  This. progressBar1.Value =Convert.ToInt32 (IPOs); }        }        #endregion                intj =0;//records the number of files that have been successfully updated                 Public voidGetbasestringtofile () {string[] Filetoname=allfile.split (',');  for(inti =0; I < Filetoname.count (); i++)            {                if(Untity.stringtofile (soap. Filetostream (Filetoname[i]), Path.GetFullPath (".\\") +"uponload\\"+Filetoname[i])) Download update file, return True to increase the progress bar {Thread.Sleep ( -); J++;                Settextmessage (j); }            }        }    }}

Haven't figured out how to cue the line loads load is complete. And then you can prompt for updates to succeed or fail ...

  #regionSave the Base64 encoded string as a file/// <summary>          ///Save the Base64 encoded string as a file/// </summary>          /// <param name= "base64string" >string after base64 overweight</param>          /// <param name= "FileName" >the path and file name of the saved file</param>          /// <returns>whether the file was saved successfully</returns>           Public Static BOOLStringtofile (stringBase64string,stringfileName) {            Try{FileStream fs=NewFileStream (FileName, FileMode.Create); BinaryWriter BW=NewBinaryWriter (FS); if(!string. IsNullOrEmpty (base64string) &&file.exists (FileName)) {bw.                Write (convert.frombase64string (base64string)); } bw.                Close (); Fs.            Close (); }            Catch            {                return false; }            return true; }        #endregion

Self-written progress bar

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.