C# Can I add values to a listbox with a backgroundwork thread


I want my background worker to add items to a list box, it appears to do so when debugging but the listbox doesn't show the values. I suspect this is something to do with adding items whilst inside the background worker thread, do I need to add these to an array and then populate the list box from the array during backgroundWorker1_RunWorkerCompleted?

Thanks for the help.

Best Answer

You can use Invoke like this:

private void AddToListBox(object oo)
    Invoke(new MethodInvoker(
                   delegate { listBox.Items.Add(oo); }