[英]“Cross-thread operation is not valid” exception when trying to get value of comboBox in Backgroundworker
I have some problem when trying to get value of combobox in IF statement in Backgroundworker. 尝试在Backgroundworker的IF语句中获取组合框的值时遇到一些问题。 When I try to run this code
当我尝试运行此代码
if (KondisiSaldo.SelectedItem == "Kurang dari...")
{
view.RowFilter = string.Format("[Saldo] < '{0}'", thresholdcas);
view2.RowFilter = string.Format("[Saldo] > '{0}'", thresholdcas);
this.Invoke(new MethodInvoker(delegate
{
ViewDataSaldoGV.DataSource = view;
SaldoUnscheduleGV.DataSource = view2;
}));
}
The error says 错误说
Cross-thread operation not valid: Control 'KondisiSaldo' accessed from a thread other than the thread it was created on.
跨线程操作无效:控件“ KondisiSaldo”从创建该线程的线程之外的其他线程访问。
Can anyone help me ? 谁能帮我 ?
You are accessesing KondisiSaldo
in non GUI thread. 您正在非GUI线程中访问
KondisiSaldo
。 Put the KondisiSaldo
in Invoke block to access it on GUI thread as your did with view
and view2
controls. 将
KondisiSaldo
放入Invoke块中,以使用view
和view2
控件在GUI线程上对其进行访问。
this.Invoke(new MethodInvoker(delegate
{
if (KondisiSaldo.SelectedItem == "Kurang dari...")
{
view.RowFilter = string.Format("[Saldo] < '{0}'", thresholdcas);
view2.RowFilter = string.Format("[Saldo] > '{0}'", thresholdcas);
ViewDataSaldoGV.DataSource = view;
SaldoUnscheduleGV.DataSource = view2;
}
}));
You may need to adjust the condition you have. 您可能需要调整条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.