C# Invoke child form hangs application random

116 Views Asked by At

In my windows form application I call, from the main MDIContainer form, a class in which I invoke the open of the child form.

In Main Form :

private void btnTemplate_ItemClick(object sender, ItemClickEventArgs e)
{
  beiProgressBar.EditValue = "Form opening in progress...";
  repositoryItemMarqueeProgressBar1.ShowTitle = true;
  beiProgressBar.Visibility = BarItemVisibility.Always;

  bwTemplate.RunWorkerAsync();
}

private void bwTemplate_DoWork(object sender, DoWorkEventArgs e)
{
  FrmTemplate frm;


  frm = new FrmTemplate();
  Callback.SetFormTemplate(this, ref frm);
}

In the Callback class I show the child form :

public delegate void SetFormTemplateCallback(FrmMain pFormMain, ref FrmTemplate pForm);

public static void SetFormTemplate(FrmMain pFormMain, ref FrmTemplate pForm)
{
  if (pFormMain.InvokeRequired)
  {
    SetFormTemplateCallback d = new SetFormTemplateCallback(SetFormTemplate);
    pFormMain.Invoke(d, new object[] { pFormMain, pForm });
  }
  else
  {
    pForm.MdiParent = pFormMain;
    pForm.InitForm();
    pForm.Show();
  }
}

This operation randomly hangs my application.

I also tried with BeginInvoke but the problem is still present.

I noticed that often the application freeze when it is minimized.

It is difficult also debug this error.

Anyone has ever reached a similar behavior ?

0

There are 0 best solutions below