cmazur

Hey Guys,

I'm in a position where my program is using too much CPU power.

My program receives roughly 100 updates for every 30 rows of data per second.

Unfortunately, I cannot cut back on the amount of updates.

I'm using the .NET Framework 2.0 and Visual Studio 2005.

When using a DataTable, and updating the DataTable without the DataGridView, the performance is flawless.

While doing this, the CPU usage is steady at 0%.

When I put the DataGridView in, the CPU usage increases dramatically.

The DataGridView is or have tried:

- DoubleBuffered to prevent flickering

- Already tried utilizing the SetStyle() method

- Have tried using DataGridView.BeginEdit() & DataGridView.EndEdit()

- I've also tried using a DataTableReader and the DataTable.Load() method, the DataTable does not load any data.

When it comes down to it, I just need to get the data and show it as fast as possible with minimal CPU usage.

Suggestions would be great. Optimiztion is very important to this endeavor!

Thanks,

Chris



Re: Windows Forms Data Controls and Databinding DataGridView Control Optimization

sirjis

Are you sure you actually need the DataGridView to be updating that fast You could perhaps synchronize the view to the data only every few seconds.

[Note, I don't know anything about database programming]





Re: Windows Forms Data Controls and Databinding DataGridView Control Optimization

cmazur

Sirjis,

The DataGridView needs to be updating this fast.

This is a must because of the importance of the data that I am dealing with.

-Chris





Re: Windows Forms Data Controls and Databinding DataGridView Control Optimization

sirjis

I don't really know if it is possible to synchronize data like I said anyway. Seems like it's possible for that to take longer than just always applying changes as they occur. But if it's not much longer, what point is there in having a 100Hz update rate on the actual view Sure, the table needs to update at 100Hz, but anything faster than say 15Hz will seem almost instantaneous to the user.

Basically, what I am saying is only true if it's the actual painting of the control that is slowing it down. If that's the case, try subclassing DataGridView and only calling base.OnPaint from the OnPaint override every nth time, with a timer that calls Invalidate every so often so you make sure to stay painted correctly. If that's not the case though, then ignore me.





Re: Windows Forms Data Controls and Databinding DataGridView Control Optimization

cmazur

Fortunately,

I already know that the problem is the repainting of the data.

I would rather be repainting 3 times per second rather than 100 times per second.

What I was trying to say before is that my attempts to refresh the DataGridView cause one of two things:

1. The data does not update (such as when using DataTableReader)

or

2. 100+ updates per second (causes very slow painting)

Anytime I change the DataSource (e.g. the DataTable), the DataGridView automatically repaints itself.

I only need to repaint the rows that have been changed or modified as well as any new additional rows.

This puts the maximum times that I would need to update the DataGridView to about 5 - 10 times per second and not the 100+ it is doing presently.

Thanks for the responses,

Chris





Re: Windows Forms Data Controls and Databinding DataGridView Control Optimization

cmazur

Does anybody have any suggestions





Re: Windows Forms Data Controls and Databinding DataGridView Control Optimization

Rong-Chun Zhang - MSFT

Hi Chris,

Did you handle the DataGridView.CellPainting event If so, you should set the properties in a DataGridViewCellPaintingEventArgs to change the appearance of the cell instead of directly accessing a cell in the DataGridView to improve performance. Also it is hard to guessm could you please show some code for us to discuss

Hope this helps.

Thanks.






Re: Windows Forms Data Controls and Databinding DataGridView Control Optimization

cmazur

Hey Rong-Chun Zhang,

Thanks for the reply. Here is the code that I am using to update the datagridview data.

I am currently not handling the DataGridView.CellPainting event.

I will look into this.

Code Snippet

//bgw is a backgroundworker

//buffTable & StreamTable are both DataTables

void bgw_DoWork(object sender, DoWorkEventArgs e)

{

while (true)

{

try

{

updateTable();

}

catch (Exception)

{ }

buffTable = StreamTable.Copy();

Thread.Sleep(300);

}

}

void updateTable()

{

for (int i = 0; i < buffTable.Rows.Count; i++)

{

try

{

StreamTable.LoadDataRow(buffTable.Rows[i].ItemArray, LoadOption.OverwriteChanges);

}

catch (Exception e){}

}

}

Thanks,

Chris





Re: Windows Forms Data Controls and Databinding DataGridView Control Optimization

timvw

I've found that setting AutoSize(Rows|Columns)Mode to None drastically improved the performance of DGV...





Re: Windows Forms Data Controls and Databinding DataGridView Control Optimization

cmazur

timvw,

I've already changed those settings, however, thanks for the suggestion.

ok all, let me rephrase my issue...

I'd like to refresh the DataGridView 5 - 10 times per second, instead of each update, which could be up to 150 times per second.

Any Suggestions

Thanks,

Chris





Re: Windows Forms Data Controls and Databinding DataGridView Control Optimization

cmazur

Well it's been a while since the last reply, so I thought I'd ask another question to go along with this topic.

Although I have not figured out the issues in performance, it seems to me that everything I find points back to implementing virtual mode for the datagridview.

Has anybody successfully implemented virtual mode with their datagridview I know there are some links here on MSDN that show examples of how to implement it, but before spending a lot of time, I'd like to make sure that virtual mode is the answer.

Thanks,

Chris