Calling a method with params on a form on a different thread, plea

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi! I need to call a method with some parameters
on a form which was created on a different thread.

Here's how I create the form:
// Main Thread:


ThreadStart entryPoint = new ThreadStart(ShowSplashForm);
Thread splashFormThread = new Thread(entryPoint);
splashFormThread.Name = "Splash form thread";
splashFormThread.Start();

...................


public static frmSplash m_SplashForm;
public static void ShowSplashForm()
{
m_SplashForm = new frmSplash();
m_SplashForm.ShowDialog();
}

I can see that the form does get created on a new thread called "Splash form
thread"

Now the problem:
The frmSplash form has a public method called
UpdateCaption(string newCaption)

How do I call it from the main thread that created this form ?
is it possible ? Any ideas/examples are highly appreciated.
 
Mike,

In the idea of a good design, I must tell you that windows forms are not
thread safe out of the box.

It is certainly possible to do so though, but the right way to do it would
be to use ContextSwitching using the invoke function. You'd need to create a
delegate to match the function signature to acheive this.

You could try going to www.gotdotnet.com under user samples and search for
"Splash Screen" for appropriate samples.

- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik
 
Back
Top