Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
There is a weird problem for which I will have to do some explanation on background.

I am working on a WPF client application which has about 3-4 usercontrols loaded, each having a listview displaying records using a observable collection. This observable collection is a collection of class instances that follow the INotifyPropertyChanged model. Upon each change in the collection the change reflects onto the listview column. Updates to existing rows in the collection keep streming in from the server using WCF TCP/IP at about 100-200 updates per second.

The issue is that once in a while the UI just freezes and then the no of threads attached to the process (seen in the task manager) keep on increasing exponentially.. I have no clue why this happens.. when i debug the updates are still coming in and observable collection is still getting updated.. but the UI hangs.. This does not happen always or on a particular action.

I am using Dispatcher.BeginInvoke when adding items to the listview but not when updating the properies of instances within the collection as observable collection automatically takes care of such updates. I am also using Virtualization in listview which is anyways enabled by default.

Any clues what could be causing this..

Posted

Suggestions,
- The only thing striking from your description is, your object implements INotifyPropertyChanged. ObservableCollection inherently implement the change notification. You might want to try disabling the property change mechanism of the objects and just rely on the ObservableCollection.
- What DispatcherPriority do you set for BeginInvoke ? Did you try setting it to a lower priority e.g. Background ?
- Don't update the main Observable collection. Work on a different one and periodically replace the main one with the updated one. I don't feel good about this one though :>
 
Share this answer
 
The issue seems to be with the wpf framework, although i am not sure. I found the solution to my problem on the following thread, which makes for a good reading.

Try this link and check out Kevin Kerr comment in later half of the thread[^]

Now i let the background thread do the updations as fast as it wants to without raising the property changed events at that time, but i raise all the property changed events for all objects in collection from the UI thread on every 100 frames using the CompositionTarget.Rendering event. Now the hang problem is thankfully put to rest!
 
Share this answer
 
v2


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900