C# WinForm BackgroundWorker not Updating Processbar -


i having little trouble getting backgroundworker update progress bar. using tutorial online example, code not working. did digging on site , can't find kind of solution. new backgroundworker/progress thing. don't understand fully.

just set things up: have main form (form 1) opens (form 3) progress bar , status label.

my form 3 code is:

public string message {     set { lblmessage.text = value; } }  public int progressvalue {     set { progressbar1.value = value; } } public form3() {     initializecomponent(); } 

my form 1 partial code:

private void btnimport_click(object sender, eventargs e) {     if (backgroundworker1.isbusy != true)     {         if (messagebox.show("are sure want import " + cbtablenames.selectedvalue.tostring().trimend('$') + " " + _db, "confirm import", messageboxbuttons.yesno) == dialogresult.yes)         {             alert = new form3(); //created @ beginning             alert.show();             backgroundworker1.runworkerasync();         }     } }  private void backgroundworker1_dowork(object sender, doworkeventargs e) {     backgroundworker worker = sender backgroundworker;     int count = 0     foreach(datarow row in datatabledata.rows)     {     /*... stuff ... */     count++;     double formula = count / _totalrecords;     int percent = convert.toint32(math.floor(formula)) * 10;     worker.reportprogress(percent, string.format("completed record {0} out of " + _totalrecords, count));     } }  private void backgroundworker1_progresschanged(object sender, progresschangedeventargs e) {     alert.message = (string) e.userstate;     alert.progressvalue = e.progresspercentage; }  private void backgroundworker1_runworkercompleted(object sender, runworkercompletedeventargs e) {     alert.close(); } 

so. problem not updating anything. progress bar nor label updating. can point me in write direction or have suggestion?

that give 0 * 10 because count , _totalrecords integer values, , integer division used here. count less total records, have formula equal 0:

double formula = count / _totalrecords; // equal 0 int percent = convert.toint32(math.floor(formula)) * 10; // equal 0 

well, when work completed, have formula equal 1. that's reason why progress not changing.

here correct percentage calculation:

int percent = count * 100 / _totalrecords; 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -