I am creating an application that should display data received from an external system. This data can be very fast, and the number of bytes that each row occupies is relatively small. This means that you need to add a lot of lines per unit of time. I am now at a point where I seem to be getting data faster than I can handle as my memory usage grows.
I think most of this is related to drawing the actual dataGridView. I made small changes to the dataGridView in the hope that this will increase performance already. (e.g. disable auto-size, special styles, etc.)
In a recent addition, I added line coloring, which was necessary. Currently my application works as follows:
- I get data from an external system
- I queue data (ConcurrencyQueue) by thread
- Another thread receives data from this queue, processes it, and adds it to the BindingList bound to the table.
Actual addition takes place in a function that has 2 parameters: 1. A list containing elements for columns (elements) 2. Color for a row. (Colour)
looks like this (semi-pseudo):
rowColors.Add(rowColor);
ResultRow resultRow = new ResultRow();
foreach(item in items)
{
resultRow.Set(item);
}
bindingList.Add(resultRow);
if (dataGrid.Rows.Count > 0)
{
dataGrid.FirstDisplayedScrollingRowIndex = dataGrid.Rows.Count - 1;
}
As the code above shows, the color that I get is added to the list that is used in the datagridview event as follows:
void DataGridCellFormattingEvent(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == dataGrid.Columns["Errors"].Index)
{
dataGrid.Rows[e.RowIndex].DefaultCellStyle.BackColor = rowColors[e.RowIndex];
}
}
BindingList is defined as follows:
BindingList bindingList;
where ResultRow is a class with a structure like this:
public class ResultRow
{
private int first = 0;
private string second = "";
private UInt64 third = 0;
private IPAddress fourth = null;
public ResultRow()
{
}
public void Set (<the values>)
{
}
public UInt64 Third
{
get { return third; }
set { third = value; }
}
, ? datagrid, , . ( ). , , , . (BindingList, , DataGridView, - , )
, - / .
-edit -
, , , , . ( )