multithreading - Thread not updating progress bar control - C# -


i have custom form custom progress bar, spawned in main class(main thread). spawn thread , send threadstart function. thread start function should update progress bar in custom control, doesnt.:

class myclass { ...... //custom form progress bar public customformwithprogressbar statusscreen = new customformwithprogressbar(0); //thread use private thread mythread;  ..... //linked button trigger update procedure. void buttonpressevent(.......) {     //create sub thread run work , handle ui updates progress bar     mythread = new thread(new threadstart(threadfunction));     mythread.start(); } ..... //the function gets called when thread runs public void threadfunction() {     //mythreadclass mythreadclassobject = new mythreadclass(this);     //mythreadclassobject.run();     statusscreen.showstatusscreen();      (int = 0; < 100; i++ )     {         statusscreen .setprogresspercentage(i);         thread.sleep(20);     }     statusscreen.closestatusscreen(); } 

now statusscreen form sits , nothing. no updates occur. have confirmed sub thread indeed created , while in threadfunction, runnin on new thread. determined through thread window in visual studio.

why updates progress percentage of status screen not being shown? how can updates push new values progress screen , have show live?

please note integer values being send status screen functions represent percentage of completion. thread.sleep see updates if/when happen.

note not re-drawing issue. call invalidate when progress percentage passed custom progress bar

you can not update controls thread.

the right way - using backgroundworker purposes. way (almost right way) - use control.invoke method. , 1 more right way - use synchronizationcontext.

but may choose dark side of power , use checkforillegalcrossthreadcalls - static property of control class , set false.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -