C#我可以添加值与backgroundwork线程列表框? [英] C# Can I add values to a listbox with a backgroundwork thread?
本文介绍了C#我可以添加值与backgroundwork线程列表框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的后台工作,以项目添加到一个列表框,它调试但列表框不显示值时,会出现这样做。我怀疑这是事做添加项目,而后台工作线程里面,我还需要在 backgroundWorker1_RunWorkerCompleted
这些添加到一个数组,然后填充从数组列表框中?
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
?
感谢您的帮助。
推荐答案
您可以使用调用像这样的:
You can use Invoke like this:
private void AddToListBox(object oo)
{
Invoke(new MethodInvoker(
delegate { listBox.Items.Add(oo); }
));
}
这篇关于C#我可以添加值与backgroundwork线程列表框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文