We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

High CPU Usage in grid group control

Hi, I am using windows form timer and update the data source every 2 second, but it's appear high cpu usage and program slightly hang and very hard to control. The following is the code, is there anyway to do the optimization??

System.Windows.Forms.Timer todayTimer = new System.Windows.Forms.Timer();
todayTimer.Tick += todayTimer_Tick;
todayTimer.Interval = 2000;
todayTimer.Start();

Timer started and running the following statements.. 

List<Person> person = this.GetPerson();

myGridGroupControl.DataSource = person;
myGridGroupControl.Update();

Thank you

10 Replies

MG Mohanraj Gunasekaran Syncfusion Team September 15, 2016 11:40 AM UTC

Hi Falcon, 
 
Thanks for using Syncfusion products. 
 
We have analyzed your scenario at our end. Since you have assigned the datasource for every 2 seconds, the grid will be refreshed and categorize all elements for every 2 seconds. So it will lead to performance impact. It is not the recommended approach to update the data. So we request you to change any of the objects of the bounded class instead of assigning whole datasource. 
We would like to suggest to use the INotifyPropertyChanged interface. If you use the INotifyPropertyChanged interface, the changes will be reflected automatically in GridGroupingControl. It does not make any performance issues. Please refer the below code snippet and refer the attached sample, 
 
Code snippet 
BindingList<Data> list = new BindingList<Data>(); 
this.gridGroupingControl1.DataSource = list; 
   

public class Data: INotifyPropertyChanged 
{ 
                public Data() : this("", "", "") 
                { 
                } 
 
                public Data(string cat_Id, string cat_Name, string desc) 
                { 
                                this.cat_Id = cat_Id; 
                                this.cat_Name = cat_Name; 
                                this.desc = desc; 
                } 
                private string cat_Name; 
                public string CategoryName 
                { 
                                get 
                                { 
                                          return this.cat_Name; 
                                } 
                                set 
                                { 
            if (this.cat_Name != value) 
            { 
                this.cat_Name = value; 
                OnPropertyChanged("CategoryName"); 
            } 
                                } 
                } 
        
                …… 
                ….. 
 
    public event PropertyChangedEventHandler PropertyChanged; 
 
    public void OnPropertyChanged(String name) 
    { 
        if (PropertyChanged != null) 
        { 
            PropertyChanged(this, new PropertyChangedEventArgs(name)); 
        } 
    } 
} 

Sample link: DataGrid 
 
Regards,   
Mohanraj G.   



FC Falcon CK September 16, 2016 06:59 AM UTC

Awesome, let me try it out and if any issue we will get back to you again.


MG Mohanraj Gunasekaran Syncfusion Team September 19, 2016 04:52 AM UTC

Hi Falcon, 
 
Thanks for your update.   
 
 We will wait until we hear from you. 
 
Regards, 
Mohanraj G. 



FC Falcon CK October 18, 2016 10:40 AM UTC

this.gridGroupingControl1.Table.SourceListChanged += Table_SourceListChanged;

void Table_SourceListChanged(object sender, TableEventArgs e)
        {
            e.Table.TableDirty = false;
        }

May I know what the above statement meant?? Because when data changed, I click on the cell, the value will switch to old value or others value, or even others row of value, very weird.. 

but after i commented out e.Table.TableDirty = false; it works nicely. 


FC Falcon CK October 18, 2016 12:07 PM UTC

Hi, there are another issue come out, after run around 30 mins or 1 hour, cpu usage around 25% on an i5 processor, and quite lagging the application. I am using binding list already.. Any possible issue ??


FC Falcon CK October 18, 2016 12:32 PM UTC

we notice some issue.. 
1. it will hang (when we dragging windows it move slows), not smooth, when the mouse cursor pointing to the gridgroupingcontrol

2. when mouse pointing to the gridgroupingcontrol any data changed will not reflect to the cell.. the cell still remain old values, but when we are moving out the cursor from the grid, the data update immediately.

Is this issue cause one of the reason hang?? Seems like graphical user interface problem.

Well, my gridgroupingcontrol has following setting. Is it because of the setting and cause the issues?


grid.TopLevelGroupOptions.ShowAddNewRecordBeforeDetails = false;
grid.TableOptions.ListBoxSelectionMode = SelectionMode.One;
grid.TableOptions.SelectionBackColor = Color.RoyalBlue;
grid.TableOptions.SelectionTextColor = Color.White;

grid.TableDescriptor.Columns[a].Appearance.AnyRecordFieldCell.Font.Bold = true;
grid.TableDescriptor.Columns[a].Appearance.AnyRecordFieldCell.TextColor = Color.White;
grid.TableDescriptor.Columns[a].Appearance.AnyRecordFieldCell.HorizontalAlignment = Syncfusion.Windows.Forms.Grid.GridHorizontalAlignment.Center;
grid.TableControlCurrentCellStartEditing += ggc_today_odd_TableControlCurrentCellStartEditing;

grid.GridVisualStyles = Syncfusion.Windows.Forms.GridVisualStyles.Office2010Black;

GridConditionalFormatDescriptor gridCondFormat = new GridConditionalFormatDescriptor();
gridCondFormat.Appearance.AnyRecordFieldCell.Interior = new Syncfusion.Drawing.BrushInfo(Color.Black);                
gridCondFormat.Appearance.AnyRecordFieldCell.Enabled = false;
gridCondFormat.Expression = "[StyleId] = 1";


GridConditionalFormatDescriptor gridCondFormat2 = new GridConditionalFormatDescriptor();                
gridCondFormat2.Appearance.AnyRecordFieldCell.Interior = new Syncfusion.Drawing.BrushInfo(Color.FromArgb(33, 38, 57));                
gridCondFormat2.Appearance.AnyRecordFieldCell.Enabled = false;
gridCondFormat2.Expression = "[StyleId] = 2";


grid.TableDescriptor.ConditionalFormats.Add(gridCondFormat);
grid.TableDescriptor.ConditionalFormats.Add(gridCondFormat2);

grid.TableModel.ColWidths.ResizeToFit(Syncfusion.Windows.Forms.Grid.GridRangeInfo.Table(), Syncfusion.Windows.Forms.Grid.GridResizeToFitOptions.IncludeHeaders);
grid.TableOptions.AllowSortColumns = false;


PM Piruthiviraj Malaimelraj Syncfusion Team October 19, 2016 01:39 PM UTC

Hi Falcon, 

Thanks for the update. 

In our last update, we had provided the solutions to update the grid while changing the data source at run time by using INotifyPropertyChanged interface. Also you can set TableDirty property to true for updating the grid by using GridGroupingControl.DataSource property instead of INotifyPropertyChanged. 
 
Query 
Response 
1. it will hang (when we dragging windows it move slows), not smooth, when the mouse cursor pointing to the gridgroupingcontrol 
 
We had analyzed this scenario and created the simple sample as per your scenario. We could not able to reproduce the issue. Could you please provide us the following details, 
 
·         Ensure whether the issue is reproduced in attached sample. 
·         We suspect that the issue may be occurred by application customization. Please provide us the customization in TableControlCurrentCellStartEditing event. 
·         Provide us the sample video which replicates the scenario or screen shots. 
·         If possible, please modify the attached sample with issue reproducible. 
These would be more useful for us to provide the exact solution at the earliest. 
2. when mouse pointing to the gridgroupingcontrol any data changed will not reflect to the cell.. the cell still remain old values, but when we are moving out the cursor from the grid, the data update immediately. 
 
 
Sample link 
 
Regards, 
Piruthiviraj 



FC Falcon CK October 19, 2016 02:28 PM UTC

Ok, let me try to reproduce using your sample.. Meanwhile, got some inquiries here.. 

1. the constructor is necessary ?? Because I did not put, will affect anything?
public Data()
            : this("", "", "")
        {
        }

2. private IContainer components; // I did not put this as well.

protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }


FC Falcon CK October 20, 2016 08:21 AM UTC

Hello, check out this sample, when you mouse over, point to the grid, cpu usage raise.. 

Attachment: WorkSample_byfalcon_82e2df49.zip


PM Piruthiviraj Malaimelraj Syncfusion Team October 20, 2016 01:49 PM UTC

Hi Falcon, 
 
Thanks for the update. 
 
We had analyzed your sample. You can remove that extra constructor and we could able to understand the scenario. In your sample project, QueryCellStyleInfo customization for changing the mouse hover color is raises the CPU utilization. You can change the mouse hover color by using TableControlCellMouseHoverEnter and QueryCellStyleInfo events. Please make use of the below code. 
 
Code example 
 
int hoveredRowIndex,hoverColIndex; 
void gridGroupingControl1_TableControlCellMouseHoverLeave(object sender, GridTableControlCellMouseEventArgs e) 
{ 
    this.gridGroupingControl1.TableControl.InvalidateRange(GridRangeInfo.Cell(e.Inner.RowIndex, e.Inner.ColIndex)); 
} 
 
private void gridGroupingControl1_TableControlCellMouseHoverEnter(object sender, GridTableControlCellMouseEventArgs e) 
{ 
    hoveredRowIndex = e.Inner.RowIndex; 
    hoverColIndex = e.Inner.ColIndex; 
    this.gridGroupingControl1.TableControl.InvalidateRange(GridRangeInfo.Cell(hoveredRowIndex,hoverColIndex)); 
} 
 
void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e) 
{ 
    if (hoveredRowIndex == e.TableCellIdentity.RowIndex && hoverColIndex == e.TableCellIdentity.ColIndex) 
     { 
        //Set the back color for the mouse hovered row. 
        e.Style.BackColor = Color.Goldenrod; 
        e.Style.TextColor = Color.Black; 
    } 
} 
 
Please refer the below KB link for further reference, 
 
Sample link 
 
Regards, 
Piruthiviraj

Loader.
Up arrow icon