G
Guest
I could really use some help here...
I am using C# 2005 and have created a splash screen that runs on a seperate
thread. I can invoke the splash screen in the Main() method, but then I
can't get rid of it! I am attempting to put a line in the Form1_Load (or
maybe Form1_Shown) that calls a static method from the splash screen to close
that form. But, when I do so, it complains about an invalid cross-thread
operation. How can I get this screen to close?
Here are the relevant parts to my splash screen:
// Static Public Method to launch Splash Screen
static public void ShowSplash()
{
if (ms_frmSplash != null) return;
ms_Thread = new Thread(new ThreadStart(frmSplash.ShowForm));
ms_Thread.IsBackground = true;
ms_Thread.SetApartmentState(ApartmentState.STA);
ms_Thread.Start();
}
// Static Private Method to Display Splash Screen
static private void ShowForm()
{
ms_frmSplash = new frmSplash();
Application.Run(ms_frmSplash);
}
// Static Public Method to Close Splash Screen
static public void CloseForm()
{
if (ms_frmSplash != null) ms_frmSplash.Close();
}
I am using C# 2005 and have created a splash screen that runs on a seperate
thread. I can invoke the splash screen in the Main() method, but then I
can't get rid of it! I am attempting to put a line in the Form1_Load (or
maybe Form1_Shown) that calls a static method from the splash screen to close
that form. But, when I do so, it complains about an invalid cross-thread
operation. How can I get this screen to close?
Here are the relevant parts to my splash screen:
// Static Public Method to launch Splash Screen
static public void ShowSplash()
{
if (ms_frmSplash != null) return;
ms_Thread = new Thread(new ThreadStart(frmSplash.ShowForm));
ms_Thread.IsBackground = true;
ms_Thread.SetApartmentState(ApartmentState.STA);
ms_Thread.Start();
}
// Static Private Method to Display Splash Screen
static private void ShowForm()
{
ms_frmSplash = new frmSplash();
Application.Run(ms_frmSplash);
}
// Static Public Method to Close Splash Screen
static public void CloseForm()
{
if (ms_frmSplash != null) ms_frmSplash.Close();
}