c# - Cross thread operation while working event raised by other object -


i have class 'userdetails' having event called 'detailschanged'. raised whenever user detail changes.
when creating new object of 'userdetails' (objuserdetails) in new form, ll subscribe event 'detailschanged' indicate user datachange.

objuserdetails.detailschanged += informtouser 

informtouser method in new form. in informtouser method accessing form's control(say label's text property).
when control accessed getting 'cross thread operation' error.
how avoid cross thread operation??

ui controls can updated ui thread. if working winforms should do:

mycontrol.invoke((methodinvoker)(() => { mycontrol.text="some text"; })); 

and if in wpf should use dispatcher:

mycontrol.dispatcher.begininvoke(dispatcherpriority.background, new action(() => mycontrol.text = "")); 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -