Filling GridView with Multiple Threads

2 posts, 1 answers
  1. Erfan
    Erfan avatar
    1 posts
    Member since:
    Jan 2016

    Posted 16 Jan 2016 Link to this post

    I'm going to fill my RadGridView by using multiple threads. My code is as follows but is not working. How can I do this?

    BackgroundWorker[] workers = new BackgroundWorker[2];
            private void frmTest_Load(object sender, EventArgs e)
                for (int col = 0; col < 300; col++)
                    grid.Columns.Add("Col " + col.ToString());
                for (int r = 0; r < 2; r++)
                    workers[r] = new BackgroundWorker();
                    workers[r].DoWork += new DoWorkEventHandler(Worker_DoWork);
                    workers[r].RunWorkerCompleted += new RunWorkerCompletedEventHandler(Worker_RunWorkerCompleted);
            void Worker_DoWork(object sender, DoWorkEventArgs e)
                var rnd = new Random();
                var info = (GridViewInfo)e.Argument;
                var row = new GridViewDataRowInfo(info);
                int i = 0;
                foreach (GridViewCellInfo cell in row.Cells)
                    cell.Value = i++;
                    cell.Style.NumberOfColors = 1;
                    cell.Style.BackColor = Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255));
                    cell.Style.CustomizeFill = true;
                e.Result = row;
            void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

  2. Answer
    Dess avatar
    2110 posts

    Posted 18 Jan 2016 Link to this post

    Hello Erfan,

    Thank you for writing.

    Note that all UI controls are not thread safe controls in the whole Windows Forms platform (not just Telerik controls, but all controls out there). Here is an article on MSDN, describing how to make thread-safe Winforms UI application. This means that any control from the Telerik UI for WinForms suite is not thread safe as well and cannot be used outside the main UI thread. You should use an Invoke to update the controls in cross threading scenario.

    I hope this information helps. Should you have further questions I would be glad to help.
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top