471,627 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

Nice Threads!

XDJ
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();
}

Feb 2 '06 #1
2 1312
Oooh! Oooh! (Doing best Horshack impression)

Perhaps you need to do this...?

static public void CloseForm()
{
MethodInvoker closeDelegate = new
MethodInvoker(ms_frmSplash.Close);
ms_frmSplash.BeginInvoke (closeDelegate );
}

I'm guessing here....

Feb 2 '06 #2
XDJ <XD*@discussions.microsoft.com> wrote:
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?


See http://www.pobox.com/~skeet/csharp/t...winforms.shtml

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ronan Viernes | last post: by
reply views Thread by Al Tobey | last post: by
34 posts views Thread by Kovan Akrei | last post: by
7 posts views Thread by Mr. Mountain | last post: by
3 posts views Thread by bygandhi | last post: by
10 posts views Thread by [Yosi] | last post: by
10 posts views Thread by Darian | last post: by
1 post views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.