c# - Update two progressbar in same time -


i have auto-upload application ftp server , 2 progressbar's update overall , current download state. first 1 works fine (update% = currentfile int / allfilestodownload *100%). i'd upload current file downloading. code:

uri url = new uri(surltodnldfile);                      int inde = files.tolist().indexof(file);                     string subpath = ...                     bool isexists = system.io.directory.exists(subpath);                     if (!isexists)                         system.io.directory.createdirectory(subpath);                     sfilesavepath = ...                     system.net.ftpwebrequest request = (ftpwebrequest)ftpwebrequest.create(new uri(file));                      system.net.ftpwebresponse response = (system.net.ftpwebresponse)request.getresponse();                     response.close();                     long isize = response.contentlength;                     long irunningbytetotal = 0;                      webclient client = new webclient();                      stream strremote = client.openread(url);                      filestream strlocal = new filestream(sfilesavepath, filemode.create, fileaccess.write, fileshare.none);                      int ibytesize = 0;                      byte[] bytebuffer = new byte[1024];                      while ((ibytesize = strremote.read(bytebuffer, 0, bytebuffer.length)) > 0)                     {                         strlocal.write(bytebuffer, 0, ibytesize);                         irunningbytetotal += ibytesize; //there i'd upload current file download status                         string = ibytesize.tostring();                         double b = double.parse(a.tostring()) / 100;                         string[] c = b.tostring().split(',');                         int d = int.parse(c[0].tostring());                         update(d); //update(int prog) {  bgworker2.reportprogress(prog); }                       }                      double dindex = (double)(irunningbytetotal);                     double dtotal = (double)isize; // code counting overal progress - works fine                     double iprogresspercentage1 = double.parse(ind.tostring()) / double.parse(files.count().tostring()) * 100;                     ind++;                     string[] tab = iprogresspercentage1.tostring().split(',');                      int iprogresspercentage = int.parse(tab[0]);                     currentfile = file;                     bgworker1.reportprogress(iprogresspercentage);                     strremote.close(); 

unfortunately still getting error, cant update progressbar2, becouse process using it. there way it? thanks

update values thru dispatcher.begininvoke methods like.

dispatcher.begininvoke(dispatcherpriority.background, new action(()=> {   progressbar2.value = newvalue; })); 

this dispatcher push work main thread holding progressbar2.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -