我认为代码很清楚
private void ucPerson_Load(object sender, EventArgs e)
{
person = new Person();
BackgroundWorker backgroundBinder = new BackgroundWorker();
backgroundBinder.DoWork += BindComboBoxes;
backgroundBinder.RunWorkerAsync();
}
private void BindComboBoxes(object sender, DoWorkEventArgs e)
{
cmbEducationLevel.DataSource = Program.eService.GetEducationLevels();
cmbNationality.DisplayMember = "Name";
cmbNationality.ValueMember = "NationalityID";
}
我得到的错误:
跨线程操作无效:控件“cmbNationality”从创建它的线程以外的线程访问。
我需要做什么才能使我background-worker
的线程能够访问组合框?