当我在 BackgroundWorker
DoWork
事件中访问 Form 控件时,它从 DatePicker 而不是从 TextBox 读取值或组合框
错误:
Cross-thread operation not valid: Control 'cmbProgram' accessed from a thread other than the thread it was created on.
代码:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
string strDate = dtpDate.Value.ToString();
string strProgram = cmbProgram.Text;
}
它如何从 DataPicker 中读取值(在不同的线程中)?
是否有任何解决方法可以从 BackgroundWorker
DoWork
事件访问表单控件?
最佳答案
使用:
Dispatcher.Invoke(new Action(() =>
{
string strDate = dtpDate.Value.ToString();
string strProgram = cmbProgram.Text;
}));
关于c# - 在 BackgroundWorker DoWork 事件中读取 ComboBox 值时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10446417/