Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WPF application with listview hangs and threads keep increasing

WPF application with listview hangs and threads keep increasing

Scheduled Pinned Locked Moved WPF
csharphelpwpfwcfdesign
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pankaj Chamria
    wrote on last edited by
    #1

    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.

    A B 2 Replies Last reply
    0
    • P Pankaj Chamria

      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.

      A Offline
      A Offline
      ABitSmart
      wrote on last edited by
      #2

      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 :>

      P 1 Reply Last reply
      0
      • P Pankaj Chamria

        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.

        B Offline
        B Offline
        BlitzPackage
        wrote on last edited by
        #3

        Can you offload any of the work to a Background Worker thread?

        1 Reply Last reply
        0
        • A ABitSmart

          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 :>

          P Offline
          P Offline
          Pankaj Chamria
          wrote on last edited by
          #4

          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.

          A 1 Reply Last reply
          0
          • P Pankaj Chamria

            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.

            A Offline
            A Offline
            ABitSmart
            wrote on last edited by
            #5

            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 :>

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups