私のアプリケーションはライブフィードからデータを取り出し、処理して結果を表示します。このデータは5秒ごとに更新されます。メインフォームのLoadイベントでは、最初のデータサイクルが実行されるまで表示されるスプラッシュ画面を表示するスレッドを作成しました。すべてのデータを取得する前にフォームが開きます。 UIスレッドが処理スレッドの最初のサイクルを待つようにするには?
データフェッチおよび処理スレッド(RecieverThread)がRecieveFeedを呼び出します。私が直面しているのは、最初のサイクルが完全に実行される前に、RecieveFeedでフェッチされたデータを表示するform2が表示されているということです。最初のサイクルがデータのフェッチを完了した後にのみ、form2がロードされるようにするにはどうすればよいですか。メインフォームで
コード:
private void frmMain_Load(object sender, EventArgs e)
{
Hide();
// Create a new thread from which to start the splash screen form
Thread splashThread = new Thread(new ThreadStart(StartSplash));
splashThread.Start();
//Thread to call the live feed engine. This thread will run for the duration of application
ReceiverThread = new System.Threading.Thread(new System.Threading.ThreadStart(ReceiveFeed));
ReceiverThread.Start();
frmSecondForm form2 = new frmSecondForm();
form2.MdiParent = this;
form2.WindowState = FormWindowState.Maximized;
Show();
form2.Show();
}
public frmRaceRace()
{
InitializeComponent();
this.splash = new SplashScreen();
}
private void StartSplash()
{
splash.Show();
while (!done)
{
Application.DoEvents();
}
splash.Close();
this.splash.Dispose();
}
private void ReceiveFeed()
{
while (!StopReceivingData)
{
foreach (...)
{
//Fetches data from live engine
DLLImportClass.GetData1();
//Manipulates and stores the data fetched in datatables
ThreadPool.QueueUserWorkItem(new WaitCallback(delegate { StoreData(); }))
rowsProcessed++;
if (!done)
{
this.splash.UpdateProgress(100 * rowsProcessed/totalRows);
}
}
done = true;
Thread.Sleep(5000);
}
}
これは、すべてのデータを取得する前にフォームが開くという問題を解決しました。 – Arcturus