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