Making sure OnPropertyChanged() is called on UI thread in MVVM WPF app

前端 未结 5 2094
执念已碎
执念已碎 2020-11-28 07:15

In a WPF app that I\'m writing using the MVVM pattern, I have a background process that doing it\'s thing, but need to get status updates from it out to the UI.

I\'m

5条回答
  •  广开言路
    2020-11-28 07:53

    This is more of an extension to the accepted answer but I did this with my event hander ...

    using System.Threading;
    
    private void Handler(object sender, RoutedEventArgs e)
    {
        if (Thread.CurrentThread == this.Dispatcher.Thread)
        {
            //do stuff to this
        }
        else
        {
            this.Dispatcher.Invoke(
                new Action(Handler),
                sender,
                e);
        }
    }
    

提交回复
热议问题