我正在使用后台工作人员循环遍历 a 中的每个项目,ListView
并在单击按钮后对其进行处理:
private void bParsePosts_Click(object sender, EventArgs e)
{
parseWorker.RunWorkerAsync(this.lvPostQueue);
}
然后,我有:
private void parseWorker_DoWork(object sender, DoWorkEventArgs e)
{
// Loop through each item
for (int i = 0; i < lvPostQueue.Items.Count; i++)
{
string title = lvPostQueue.Items[i].SubItems[0].ToString();
string category = lvPostQueue.Items[i].SubItems[1].ToString();
string url = lvPostQueue.Items[i].SubItems[2].ToString();
lvPostQueue.Items[i].SubItems[3].Text = "Done";
}
}
但是,我收到此错误:
Cross-thread operation not valid: Control 'lvPostQueue' accessed from a thread other than the thread it was created on.
我将如何lvPostQueue
从该后台工作人员中操作控件?
谢谢。