我要开始新话题了:
Thread t = new Thread(UpdateListOutput);
t.IsBackground = true;
t.Start();
更新列表输出:
void UpdateListOutput()
{
while (true)
{
if (!string.IsNullOrEmpty(engineOutput))
{
OutputBox.Items.Add(engineOutput);
}
}
}
我收到错误:
Cross-thread operation not valid: Control 'OutputBox' accessed from a thread other than the thread it was created on.
我该如何运行它?
最佳答案
试试这个
this.Invoke((MethodInvoker)(() => OutputBox.Items.Add(engineOutput)));
关于c# - 如何从其他线程将项目添加到列表框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18534458/