我有一个GUI,其中包含主窗体上的列表框中的测试脚本列表。我希望BackgroundWorker
根据从列表框中选择的项目执行不同的脚本。有条件的BackgroundWorker场景
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
if(listbox.SelectedItem.ToString() == test1)
{
testcase test1 = new testcase(); // instantiate the script
test1.script1(); // run the code
}
}
然而,当我尝试这样做,我得到的消息InvalidOperationException occurred
因为我尝试进行跨线程操作。是否有另一种方式来完成这项任务?
我只能得到'this.Invoke' – Nevets
@nevets你在WPF或的WinForms?两者的语法略有不同。这个概念是一样的 – middelpat