Understanding the Silverlight Dispatcher

后端 未结 2 399
无人及你
无人及你 2020-12-14 01:32

I had a Invalid Cross Thread access issue, but a little research and I managed to fix it by using the Dispatcher.

Now in my app I have objects with lazy loading. I\'

2条回答
  •  情书的邮戳
    2020-12-14 02:14

    If you use the MVVM light toolkit you could use the DispatcherHelper class in the Galasoft.MvvmLight.Threading namespace in the Extras dll. It checks the access and uses a static property for the dispatcher, similar to the SmartDispatcher.

    In your App.xaml.cs startup event call:

    DispatcherHelper.Initialize();
    

    Then anywhere you need to use a dispatcher use:

       DispatcherHelper.CheckBeginInvokeOnUI(() => // do stuff; );
    

提交回复
热议问题