c# - how wait thread with parameters and doesn't freeze main thread -


i write code, call thread parameters. program windows forms. how change code, wait thread, , gui of program not freeze?

var t=new thread(()=>somemethod(someparameter)); t.start(); //t.wait? 

if don't have await available, simplest solution use backgroundworker:

var bw = new backgroundworker();  bw.dowork += (sender, args) => {     // lengthy stuff here -- happen in separate thread     ... }  bw.runworkercompleted += (sender, args) => {     if (args.error != null)  // if exception occurred during dowork,         messagebox.show(args.error.tostring());  // error handling here      // put here stuff wanted put after `t.wait`     ... }  bw.runworkerasync(); // start background worker 

runworkercompleted runs in ui thread, able update ui there (as opposed stuff happening in dowork).


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -