开发者

Cross Thread Exception in PropertyChangedEvent in WPF

I have a ListView that is binded to my custom collection.

At run time , I am updating the certain properties of my entity in my custom collection in my ViewModel. At the same time , I am also doing the custom sorting in the listview.

The custom sorting is applicable when I click on the any column header of the listview.

开发者_如何学JAVA

For example, I am updating the current datetime on my entity on every 5 seconds and simulaneously , I am applying custom sorting based on DateTime.

(The Listview is third party control).

Hence I am doing two operations on my custom collection at the same time.

Should I pass the dispatcher of my control in the view model and call any methods ( which updates any entity in my custom collection ) through UI dispatcher ?


Are you using your thread only for updating the entity properties? If so, using dispatcher will result in erasing the meaning of using a thread since all the operation will be done by UI thread ultimately. You can better put your sorting logic in a different thread. Some code would help anyways.


If you want to update the UI, you have to use the dispatcher, there is no other way to update the UI.

 Dispatcher.BeginInvoke(DispatcherPriority.Background, 
                        (Action) delegate
                        {
                            //You can update your UI here 
                        });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜