在我的后台工作人员中,它需要调用另一个带有 out 参数的类的方法。
[1级]
public partial Class1 : Form
{
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
DataGridView gv;
int param1, param2;
Class2 class2 = new Class2();
class2.method(gv, out param1, out param2);
}
}
【2级】
public Class2
{
public void method(DataGridView gv, out int param1, out int param2)
{
param1 = 0;
param2 = 0;
// basically grab the data in dataGridView and load into database
}
}
我应该如何正确调用Class2.method
而不会出现错误Cross-thread operation not valid: 'class2' accessed from a thread other than the thread it was created
?