c# - In the execution of a program, are events like threads? WPF -


i have background worker thread continuously updating data displayed in window network source. have button fire event.

my question is, @ stage (relative background worker execution) event method executed? similar threads in happen simultaneously? i.e, background worker still running whilst button click method executing? in case, need use locking. or background worker pause until button click method has terminated?

events raised ui controls (e.g. buttons) execute in main thread, a.k.a. ui thread. events raise raised on whatever thread raise them on. event raisings block execution of own thread until complete. they're not special, when call them: little syntactic sugar around calling arbitrary list of delegates.

in absence of explicit synchronization code, other threads humming along background merrily continue execute.

if need or want communicate between event handler in ui thread , worker thread, you'll need write explicit code so. nothing special here: 2 threads.

and if you've got both event handler , thread putting greasy little mitts on same object, , if operations on object not atomic, you're correct: you'll need locking. thread-safe collections may come in handy.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -