I have a class ‘userdetails’ which is having a event called ‘detailschanged’. It will be raised whenever the user detail changes.
When i am creating a new object of ‘userdetails’ (objUserDetails) in my new form, i ll subscribe to event ‘detailschanged’ to indicate the user about the datachange.
objUserDetails.detailschanged += InformtoUser
InformtoUser is a method in new form. In InformtoUser method i am accessing form’s control(say label’s text property).
When the control is accessed I am getting ‘Cross Thread Operation’ error.
How to avoid this cross thread operation??
UI controls can only be updated from UI thread.
If you are working with WinForms you should do:
And if you are in WPF then you should use the dispatcher: