c# - Threads, events and the GUI -


i bit confused how gui can used in multi-threaded applications.

i hear there thing called ui thread. assume main executing thread @ startup of application.

i hear (though not 100% on this) doing ui stuff on other (non ui) threads bad idea.

so, if create separate thread , want call myform myform = new myform(); myform.showdialog(); in it, changes need make "safe"?

also, have had people tell me events spun out on different thread. (though not sure believe this.) if are, confused. can open dialog (ie myform.showdialog() in event , nothing horrible happens. (maybe depends on if event delegate called invoke or begininvoke?)

here few bits of info may out. you're saying working ui on non ui threads isn't bad idea, you'll exception. meaning, if create form in main thread, , spawn off background thread processing , want update form in background thread, it'll throw exception. in example though, create form in background thread, should ok. i'd question design, won't blow as long touch ui in same thread.

as events, events handlers executed on same thread raised on. meaning, if have form on 1 thread spawns off work on thread raises events, before doing so, hook event on form thread, need careful not touch ui directly in event handlers, because event handlers being called on background thread.

finally, way correctly manipulate ui background thread, calling invoke , passing in delegate ui work want. hth


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -