Every time I update the view of my program from a thread other than the element was created from, I use:
if (this.table.InvokeRequired)
{
this.table.Invoke(new MethodInvoker(delegate
{
this.table.Controls.Add(newRow);
this.table.Controls.SetChildIndex(newRow, this.table.Controls.Count);
}));
}
else
{
this.table.Controls.Add(newRow);
this.table.Controls.SetChildIndex(newRow, this.table.Controls.Count);
}
Even though this approach works fine, I doubt that it's the best-practice to do it that way since
this.table.Controls.Add(newRow);
this.table.Controls.SetChildIndex(newRow, this.table.Controls.Count);
is basically the same for invoking and not invoking.
Any ideas how I could improve that?