I’m writing an application which fetches data from a live engine and works on it. This data is updated every 5 seconds.
Now I’d like to have a splashscreen that shows the progress bar for the first cycle of data fetching. Once the data is fetched for the first time, the application opens the main form showing the data fetched. From hereon the main form fetches data in a loop every 5 seconds.
I’ve put the code for opening main form in the ProgressChanged event of BackgroundWorker.
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = Math.Min(e.ProgressPercentage, 100);
if (progressBar1.Value == 100)
{
SplashScr.ActiveForm.Hide();
frmMainForm frmMain= new frmMainForm();
frmMain.WindowState = FormWindowState.Maximized;
frmMain.Show();
}
}
Is there any way of just closing the Splashscreen once Main form has loaded or is this implementation Ok?
I am going to assume that in your
Program.Mainyou have something along these lines:If so it is the reason why your application is closing when you close the splash form. Try something like this:
Then from the main form you show your splash form and handle it from that end.
HTH