3

I have being battling with this problem quite a few days. It seems every single example i have seen relies on present data. But in my case i have a stream that is processed and splitted into a number of string Arrays and with these i populate my DGVs. The only (working) solution is this

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 explaining :

  • dtblRepository an Array of DataTables (for the time being it provides the index but later maybe i will dump it
  • dgvRepository an Array holding the DGVs
  • dataToAdd BlockingCollection populated from another routine
  • activeDatas an Array holding the elements by which the stream will be processed And yes all the code depends on Application.DoEvents() The whole code runs by this: trd = new Thread(AddRowsToDGVs); trd.Start()

Eveyone seems to point to async/await but i just can't find a sample that fits my needs....can i get some help :)

Wim Ombelets
  • 5,097
  • 3
  • 39
  • 55
John
  • 974
  • 8
  • 16
  • Have a look [here](http://www.aboutmycode.com/reactive-extensions/using-reactive-extensions-for-streaming-data-from-database/) on how to use [Reactive Extensions](https://msdn.microsoft.com/en-us/library/hh242985(v=vs.103).aspx) with streaming data. Might not be an actual answer at all but might change your point of view. Read up on SqlDependency, SignalR, ... as well. Lots of cool insights! – Wim Ombelets Jul 28 '17 at 12:12
  • It seems interesting but like all the other examples it justs gets around the problem of having a responsive UI while loading data from existing data... – John Jul 31 '17 at 05:41

0 Answers0