c# - Updating image via Dispatcher still gives "different thread owns it" error -


I am trying to update an image from an event in my UI in a different thread. I am using a display (based on this question) to do this, but still "calling thread can not access this object because it is a different thread" - i.Source = s Error message; . What is the right way to do this?

Zero Screen (Object Sender, EventErgus E) {ImageSource s = e.Image; Dispatcher.BeginInvoke ((Action) ((=)> Update UI (myImage, s)); } Zero UpdateUI (Image I, ImageSource s) {i.Source = s; }

Thanks a lot for any suggestions!

The image source created in the background thread was not assigned as the source of the UI control can go.

And to get the actual sender related to image control, myImage.Dispatcher :

  myImage.Dispatcher.BeginInvoke ( Action) Representative {ImageSource s = e.Image; UpdateUI (myImage, s);});   

OR

call freeze () on ImageSource before assignment. Freeze objects can be reached in the thread.


Comments