c# - Progress bar displaying execution of a method -
i don't know how display execution of method in compact .net framework. example have method (eg. upload() or print()) takes time (in cases big interval) finish.i want user can see progression of time-consuming task (eg. upload()) on progress bar.
i tried doing thread
, threadpool.queueuserworkitembut
i'm stuck. problem don't know how sync thread of method , progressbar.
please help.
i hope help:
progressbar pg = new progressbar(); pg.maximum = 100; pg.step = 1; this.controls.add(pg); new thread(new threadstart(() => { // replace code: (int = 0; < 100; i++) { if (pg.invokerequired) pg.invoke(new threadstart(() => { pg.performstep(); })); else pg.performstep(); } })).start();
this part important, or exception:
if (pg.invokerequired) pg.invoke(new threadstart(() => { pg.performstep(); })); else pg.performstep();
Comments
Post a Comment