The calling thread cannot access this object because a different thread owns it.How do i edit the image?

后端 未结 3 1062
情歌与酒
情歌与酒 2020-12-12 01:22

i know there\'s a lot of these type of questions. i wanted to post so that i can share my specific prob because im getting frustrated.

im running a thread which quer

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 01:45

    As Jon Skeet said, you can use Dispatcher.Invoke to assign the image, but it's not enough, because the BitmapImage has been created on another thread. To be able to use it on the UI thread, you need to Freeze it before:

    logo.Freeze();
    Action action = delegate { image1.Source = logo; };
    image1.Dispatcher.Invoke(action);
    

提交回复
热议问题