WPF application with listview hangs and threads keep increasing
-
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..
Pankaj Chamria, Software Programmer.
-
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..
Pankaj Chamria, Software Programmer.
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 :>
-
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..
Pankaj Chamria, Software Programmer.
Can you offload any of the work to a Background Worker thread?
-
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 :>
Thanks for your reply. I am using two collections. Collection A is a list of objects which implement INotifyPropertyChanged. It gets updated continuosly using a worker thread. Collection B is my observable collection hosted in the UI thread, which observes on Collection A elements. I used Normal priority. Using Background too causes this issue, although it occurs less frequently. 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. http://social.expression.microsoft.com/Forums/en-US/wpf/thread/e55530dc-a358-4c6b-81b6-25a11c173a22/[^] 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! PS: You mentioned that even without raising the property changed events, my listview should get updated as I am using the observable collection. But I tested it out. It does not work without raising the PropertyChanged event, for my design of using 2 collections.
Pankaj Chamria, Software Programmer.
-
Thanks for your reply. I am using two collections. Collection A is a list of objects which implement INotifyPropertyChanged. It gets updated continuosly using a worker thread. Collection B is my observable collection hosted in the UI thread, which observes on Collection A elements. I used Normal priority. Using Background too causes this issue, although it occurs less frequently. 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. http://social.expression.microsoft.com/Forums/en-US/wpf/thread/e55530dc-a358-4c6b-81b6-25a11c173a22/[^] 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! PS: You mentioned that even without raising the property changed events, my listview should get updated as I am using the observable collection. But I tested it out. It does not work without raising the PropertyChanged event, for my design of using 2 collections.
Pankaj Chamria, Software Programmer.
The article was definitely a nice read. You did not mention that you were working with 2 collections. The fine frequency of update would be causing WPF go bonkers, I sensed that and so provided you the third option. I had faced something similar when WPF was beta. I needed updates as fast as 100ms with plotting on a WPF graph. The app just died away! Microsoft recommendation was wait for the 3.0 release having performance boosting. I settled with DirectX plotting finally. It's great to know you've got things sorted out. Have fun :>