R
RYoung
Hello all,
I've got a need to display a splash screen while the main form loads. The
main form will be doing some initialization and posting messages to the
splash screen for display. Here is what I have in a nutshell (irrelevant
methods omitted):
public class SplashScreeen : Form
{
private delegate void DisplayStatusDelegate( string msg );
public void DisplayStatus( string msg )
{
if ( label1.InvokeRequired )
{
label1.BeginInvoke( new DisplayStatusDelegate( DisplayStatus ),
new object[]{ msg } );
}
else
{
label1.Text = msg;
}
}
public void ShowSplash()
{
this.ShowDialog();
}
}
// MainForm.TopMost = true
public class MainForm : Form
{
private void MainForm_Load( ... )
{
SplashScreen splash = new SplashScreen();
Thread splashThread = new Thread( new ThreadStart(
splash.ShowSplash ) );
splashThread.Start();
splash.DisplayStatus( "Initializing" );
Thread.Sleep( 1000 );
splash.DisplayStatus( "Sleeping" );
Thread.Sleep( 2000 );
splash.DisplayStatus( "Finished" );
Thread.Sleep( 1000 );
splash.Close();
splashThread.Abort();
Activate();
}
}
Everything works as expected. The Thread.Sleep calls will be replaced with
intialization routines for the app.
Any comments as to what could be wrong with this implementation is
appreciated.
Ron
I've got a need to display a splash screen while the main form loads. The
main form will be doing some initialization and posting messages to the
splash screen for display. Here is what I have in a nutshell (irrelevant
methods omitted):
public class SplashScreeen : Form
{
private delegate void DisplayStatusDelegate( string msg );
public void DisplayStatus( string msg )
{
if ( label1.InvokeRequired )
{
label1.BeginInvoke( new DisplayStatusDelegate( DisplayStatus ),
new object[]{ msg } );
}
else
{
label1.Text = msg;
}
}
public void ShowSplash()
{
this.ShowDialog();
}
}
// MainForm.TopMost = true
public class MainForm : Form
{
private void MainForm_Load( ... )
{
SplashScreen splash = new SplashScreen();
Thread splashThread = new Thread( new ThreadStart(
splash.ShowSplash ) );
splashThread.Start();
splash.DisplayStatus( "Initializing" );
Thread.Sleep( 1000 );
splash.DisplayStatus( "Sleeping" );
Thread.Sleep( 2000 );
splash.DisplayStatus( "Finished" );
Thread.Sleep( 1000 );
splash.Close();
splashThread.Abort();
Activate();
}
}
Everything works as expected. The Thread.Sleep calls will be replaced with
intialization routines for the app.
Any comments as to what could be wrong with this implementation is
appreciated.
Ron