Populating multiple Datagridviews with streaming data

I've been struggling with this issue for quite a few days. It seems like every single example I've seen relies on real data. But in my case, I have a stream that is processed and split into multiple lines of arrays and with these I populate my DGVs. The only (working) solution is

public void AddRowsToDGVs()
{  
    for (int i = 0; i < dtblRepository.Length; i++)
    {
        if (dgvRepository[i].InvokeRequired)
        {
            dgvRepository[i].Invoke(new MethodInvoker(delegate
            {
                foreach (String[] datao in dataToAdd.GetConsumingEnumerable())
                {
                    int indexOfDGV = Array.IndexOf(activeDatas, datao[0]);
                    dgvRepository[indexOfDGV].Rows.Insert(0, datao);
                    dgvRepository[indexOfDGV].Refresh();
                    Application.DoEvents();
                }
            }));
        }
        else
        Application.DoEvents();                   
    }
}

      

Some explain:

  • dtblRepository is an array of arrays of data (at the moment it provides the index, but later, maybe I'll reset it.
  • dgvRepository array containing DGV
  • dataToAdd BlockingCollection populated from another procedure
  • activeDatas Array containing elements with which the stream will be processed AND yes, all code depends on Application.DoEvents()

    All code works as follows: trd = new Thread(AddRowsToDGVs);

    trd.Start()

Eveyone seems to point to async / await, but I just can't seem to find a pattern that suits my needs .... can I get some help :)

+3


source to share





All Articles