Beste Möglichkeit, ein Fortschrittsformular anzuzeigen, während eine Methode Code ausführt?

Ich habe eine WinForm-Lademethode, die lange dauert, um einige Daten zu sammeln, die dem Benutzer angezeigt werden sollen.

Ich zeige ein Formular mit einer großen Schriftart mit dem Wort "Loading" an, während diese Methode ausgeführt wird.

Manchmal tritt dieser Fehler jedoch auf und das Fortschrittsformular "Laden" wird nicht geschlossen, und schließlich wird meine gesamte Anwendung einfach beendet:

Fehler beim Erstellen des Fensterhandles. bei System.Windows.Forms.NativeWindow.CreateHandle (CreateParams cp)

Gibt es eine bessere Möglichkeit, mein Fortschritts- / Ladeformular anzuzeigen, während ich Code in der Lademethode ausführe?

Das ist mein Code:

//I launch a thread here so that way the Progress_form will display to the user
//while the Load method is still executing code.  I can not use .ShowDialog here
//or it will block.

//Progress_form displays the "Loading" form    
Thread t = new Thread(new ThreadStart(Progress_form));  

t.SetApartmentState(System.Threading.ApartmentState.STA);
t.IsBackground = true;
t.Start();

//This is where all the code is that gets the data from the database.  This could
//take upwards of 20+ seconds.

//Now I want to close the form because I am at the end of the Load Method                         

try
{
   //abort the Progress_form thread (close the form)
   t.Abort();
   //t.Interrupt();
}
catch (Exception)
{
}

Antworten auf die Frage(3)

Ihre Antwort auf die Frage