Reznor13
Reznor13

Reputation: 181

Show loading form

I have an application where I need to display a loading form on some actions. So, I have a button that opens a form, and when I click on this button I need to display my loading form. I use the following code:

private void diligênciasToolStripMenuItem1_Click(object sender, EventArgs e)
{
LoadingWindow loadingWindow = new LoadingWindow();
try
 {
  loadingWindow.Show();
  Cursor.Current = Classe_Cursor.LoadCustomCursor(@"D:\Wait (1).ani");
  FormConsultaDiligencia Childform = new FormConsultaDiligencia();
  Childform.MdiParent = this;
  Childform.Show();
  Cursor.Current = Cursors.Default;
  loadingWindow.Close();
 }
 catch (Exception ex)
 {
  MessageBox.Show("" + ex.Message);
 }
}

When I click this button the LoadingWindow opens, but the items that I have inside the form don't work: enter image description here

All appears like blank, and it would appear like:

enter image description here

What is happening here? I can't get there alone, can someone explain to me what is the problem?

Upvotes: 0

Views: 1962

Answers (2)

Vlad
Vlad

Reputation: 1439

This occurs because you show form and execute prolonged operations into GUI thread. You should execute this operations in backgroung thread. EDIT: code removed.

Upvotes: 2

LPs
LPs

Reputation: 16223

After the istruction loadingWindow.Show() the click function is hang by loadingWindow that seems no filled with components.

The code restart from Cursor.Current = Classe_Cursor.LoadCustomCursor(@"D:\Wait (1).ani") after the user close the loadingWindow.

The istruction loadingWindow.Close() is an error: at that point the loadingWindow is already closed.

I guess you have to load animation and strings in constructor of loadingWindow.

Anyway I think you need to use a thread to perform the creation of Childform. At the end that thread will send a close request to loadingWindow and start to show Childform.

Solution proposed by adv12 will be your gol easely.

Upvotes: 0

Related Questions