2

I use a DataGridView to monitor IO events. Each time a new IO event occurs, the DataGridView is populated with a new item containing a timestamp among other data. These updates come every 10 ms, and I want to place the new items at the top of the grid.

I only need to keep ~100 rows in the grid; the older ones should be discarded as to not consume memory. All my attempts have proven to be too slow, do you have any ideas on how to approach this?

Simon
  • 191
  • 2
  • 8

1 Answers1

1

Displaying ticking data is quite challenging task. One of the biggest step to improve performance can be reducing refresh rate to a number recognizable by human eye - 20 refreshes per second without reacting to each and every IO event.

  1. Create or use a ring buffer to store 100 records only and reduce GC / memory.
  2. Use Dispatcher timer and schedule a grid refresh every 50ms. At the timer tick, grab the buffer data into the preallocated collection and refresh the Grid entirely.

You can then further improve the implementation by optimizing step 2 - say reducing measures of the cells.

Alex des Pelagos
  • 1,170
  • 7
  • 8
  • Ok, so I created a RingBuffer that implements IList, ICollection, IEnumerable and IEnumerable. However, when I bind this to the DataGridView (through a BindingSource), the DataGridView displays the properties of the RingBuffer instead of its items. Any ideas? – Simon Jun 25 '14 at 10:16
  • 1
    I'd just copy the state of the RingBuffer to a new collection. "grab the buffer data into the preallocated collection and refresh the Grid entirely". Binding to a collection which is constantly changed in background is not a good idea. – Alex des Pelagos Jun 25 '14 at 14:12