WPF/Multithreading: UI Dispatcher in MVVM

前端 未结 7 1355
有刺的猬
有刺的猬 2020-12-24 09:49

So say in an MVVM environment, I\'m in a background thread and I\'d like to run an update on a ui control. So normally I\'d go myButton.Dispatcher.BeginInvoke(blabla) but I

7条回答
  •  一向
    一向 (楼主)
    2020-12-24 10:09

    Pass the UI thread's dispatcher to the ViewModel's constructor and store it in the VM.

    Take note that each thread may have its own dispatcher. You are going to need the UI thread's!

提交回复
热议问题