I have a c# Winforms application that receives data from serial port, then process it and displays on a listview.
Receiving data at 100ms works well, but when the source transmitting rate is changed to 10 milliseconds, the application hangs after a minute or 2 minutes.
Details:
The app receives data in bytes, so I need to convert to strings, store in arraylist and fill it into the listview columns, few conversions are involved in the operation:
- byte to strings
- few conversion string to integers.
I am also using normal listview code which looks like this:
ListViewItem item = new ListViewItem(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff"));
item.SubItems.Add(hex1.ToString());
item.SubItems.Add(hex2.ToString());
.....
listView1.Items.Add(item);
so i am not sure whats wrong. is it the listview cannot handle the rate that data is coming?
any suggestion why the application hangs at that speed?
I expect that the listview is redrawing itself after each item is inserted. If it takes longer to redraw than the interval between insertions, you’ll get it hanging up. Of course, this gets worse and worse as the list grows longer.
You could perhaps fix it by accumulating batches of updates, and calling ListView.BeginUpdate() before inserting a batch, and ListView.EndUpdate() after inserting the batch.