如何将父表单设置为在C#中从类打开的表单?

时间:2016-06-29 14:39:02

标签: c# multithreading winforms

我有一个父表单protected override void OnActivityResult(int iRequestCode, Android.App.Result oResultCode, Intent oIntent) { base.OnActivityResult (iRequestCode, oResultCode, oIntent); iValue = oIntent.Extras.GetInt("MYVALUE", -1); //=> 1234567890 } ,它会调用一个类AddEmployee,而类会打开另一个(子)表单Worker。我想将InformationFetching设置为AddEmployee的父格式,但我收到了跨线程错误。

InformationFetching

有人可以建议我在这里缺少什么吗?

1 个答案:

答案 0 :(得分:1)

根据评论,我建议这样:

private void brnContinue_Click(object sender, EventArgs e)
{
  Worker workerObject = new Worker(this);
  Thread thrd = new Thread(() =>
  {
    Invoke(new MethodInvoker(delegate
    {
      addNewAccount();  // Do something heavy for 30s
      workerObject.DoWork();
    }));
  });
  thrd.Start();
}

private void addNewAccount()
{
  validatorClass objClass = new validatorClass();
  bool isSuccess = false;
  isSuccess = objClass.verifyDetails(parameters);
}