Skip to main content

Optimal Grid update

Comments

2 comments

  • Dapfor Team

    Dear Deepak,

    Your architecture is not optimal to get the maximum of performance. Firstly, you shouldn’t call BeginUpdate/EndUpdate because the call of Grid.EndUpdate leads to repainting of the entire surface. Then the BindingList takes a lot of resources especially when you add data to the beginning.

    From our point of view when the timer ticks in the GUI thread you should take all newly added trades and add them to the grid directly using Grid.Rows.Add(_data_object_). If there are multiple trades in the cache then all of them should be added in the same timer’s tick. In this case no WM_PAINT messages come to the grid while row adding. When you leave the timer’s handler, the grid will receive WM_PAINT message once for all added trades. Moreover the grid has also internal algorithms to improve performance when bulk rows are added in the GUI thread.

    Look at the example demonstrating this approach:

     

    //Initialize GUI timer
    _timer.Interval = 15;
    _timer.Tick += delegate
    {
        //Protect the _cache container
        lock(_cache)
        {
            //Copy all objects to the grid
            foreach (object o in _cache)
            {
                Row row = grid.Rows.Add(o);
                row.ChildIndex = 0;
            }
            //Clear the cache
            _cache.Clear();
        }
    };
    _timer.Start();

     

    Best regards,

    Dapfor

     

    0
  • Michael Sage

    Thanks for the Update. I will try this out and let you know what I see.

     

    0

Please sign in to leave a comment.

Powered by Zendesk