M
mike c
I am trying to create a simple splash screen to be displayed by my
application while it is initializing. Basically, I want to:
1. load the splash screen in a separate thread
2. periodically call a method on the splash screen to update a status
message in the splash
3. close the splash screen and end the thread once the main app has
initialized.
I can launch and run the screen in a separate thread, and close it
when it is done, but i cannot figure out how to call the SetStatus
method and pass it a string.
Here is a snippet of the code:
///////////////MainForm.cs/////////////////////
static SplashForm splash;
static public void StartSplash()
{
splash = new SplashForm();
Application.Run(splash);
///initialization
splash.Invoke(new EventHandler(splash.Close));
splash.Dispose();
splash = null;
}
private void init()
{
System.Threading.Thread splashThread = new
System.Threading.Thread(new
System.Threading.ThreadStart(StartSplash));
splashThread.Start();
}
//////////////SplashForm.cs//////////////////////
I need to call the following function within the SplashForm class:
public void SetStatus(string msg)
{
this.statusField.Text = msg;
}
splash.Invoke(new EventHandler(splash.Close));
splash.Dispose();
splash = null;
//////////////////////////////////////////////////
However, I cannot figure out how to call the SetStatus method, since
it is being called from a different thread.
I know this has to be something simple, but I have been banging my
head on this, and looking for examples for about 2 days.
Anyone have any suggestions?
mike c
application while it is initializing. Basically, I want to:
1. load the splash screen in a separate thread
2. periodically call a method on the splash screen to update a status
message in the splash
3. close the splash screen and end the thread once the main app has
initialized.
I can launch and run the screen in a separate thread, and close it
when it is done, but i cannot figure out how to call the SetStatus
method and pass it a string.
Here is a snippet of the code:
///////////////MainForm.cs/////////////////////
static SplashForm splash;
static public void StartSplash()
{
splash = new SplashForm();
Application.Run(splash);
///initialization
splash.Invoke(new EventHandler(splash.Close));
splash.Dispose();
splash = null;
}
private void init()
{
System.Threading.Thread splashThread = new
System.Threading.Thread(new
System.Threading.ThreadStart(StartSplash));
splashThread.Start();
}
//////////////SplashForm.cs//////////////////////
I need to call the following function within the SplashForm class:
public void SetStatus(string msg)
{
this.statusField.Text = msg;
}
splash.Invoke(new EventHandler(splash.Close));
splash.Dispose();
splash = null;
//////////////////////////////////////////////////
However, I cannot figure out how to call the SetStatus method, since
it is being called from a different thread.
I know this has to be something simple, but I have been banging my
head on this, and looking for examples for about 2 days.
Anyone have any suggestions?
mike c