multithreading - how to update process bar in c# in another thread which are execute in another class -



multithreading - how to update process bar in c# in another thread which are execute in another class -

i working on windows form want update progress bar thread thread execute code of class like:

class form1 { //start thread in class //which execute sec class method } class sec { //in class want update progress bar }

exactly i'm working files , read files in "second class" 1 1 if processing on 1 file completed want update process bar (this whole process run in thread not ui thread) . how can this. give thanks you

if want invoking yourself, this:

//this goes in form1 private void button1_click(object sender, eventargs e) { thread t = new thread(workthread); t.start(); } private void workthread() { dosomework w = new dosomework(); w.work(); while (w.progress < 100) { updatefromthread(w.progress); thread.sleep(100); } } private void updatefromthread(int progress) { if (this.invokerequired) { methodinvoker mydelegate = delegate { updatefromthread(progress); }; this.invoke(mydelegate); } else { progressbar1.value = progress; } } //class work. class dosomework { public int progress { get; set; } public dosomework() { progress = 0; } public void work() { thread t = new thread(workthread); t.start(); } private void workthread() { (int = 0; < 100; i++) { progress += 1; thread.sleep(250); } } }

you didn't give specifics far trying exactly, general idea. backgroundworkers cleaner.

c# multithreading user-interface progress-bar

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -