SplashScreen : Calling a method in a seperate thread from main form

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top