ユーザーに表示するデータを収集するのに長い時間がかかる WinForm ロード メソッドがあります。
このメソッドの実行中に、「Loading」という単語を含む大きなフォントのフォームを表示します。
ただし、このエラーが発生し、「読み込み中」進行状況フォームが閉じず、最終的にアプリケーション全体が終了することがあります。
ウィンドウ ハンドルの作成中にエラーが発生しました。System.Windows.Forms.NativeWindow.CreateHandle (CreateParams cp) で
load メソッドでコードを実行しているときに、進行状況/読み込みフォームを表示するより良い方法はありますか?
これは私のコードです:
//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)
{
}