multithreading - Code in button click c# happens after the function finishes -


i have simple c# code triggered on button press. button press first clears listboxes, changes text of label, , calls function.

private void button1_click(object sender, eventargs e) {     listbox1.items.clear();     listbox2.items.clear();     listbox3.items.clear();     listbox4.items.clear();     label5.text = "getting links...";     process(url);     label5.text = "finished"; } 

but lists cleared , label changed after process() finished executing. ruins purpose i'm changing label user aware action taking place. how can make initial label change before function process() finishes?

if process method long-running, can cause ui freezing , prevent ui redrawing - that's why don't see label text immediate update.

simpliest way achieve goal - call label5.refresh() right after label5.text = "getting links...";, cause invalidation , redrawing of label.

or can call this.refresh() if more 1 control should updated - update whole usercontrol or form owns controls.

but note - if process method runs very long time (more 2-3 seconds example) - should consider doing asyncroniously in thread separate ui. considered "good style" because not cause ui freezing.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -