在c#中使用Backgroundworker时,我遇到了跨线程操作错误。
private void IndexForm_Load(object sender, EventArgs e)
{
BG.RunWorkerAsync();
}
private void BG_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
List<int> _i = new List<int>();
_i.Add(2);
dataGridView1.DataSource = _i;
}
如果我填充Combobox就好了。例如
RunWorkerCompletedEventArgs e)
{
List<int> _i = new List<int>();
_i.Add(2);
comboBox1.DataSource = _i;
}
无法理解原因。