By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,940 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,940 IT Pros & Developers. It's quick & easy.

Application.ExitThread hides a form not associated with its message pump

P: n/a
Hi there movers & shakers,

The example below demonstrates a behaviour that is anoying the tits off of
me! It doesn't happen whilst debugging from the IDE only when you run the
compiled exe from windows explorer. I'm basically trying to display a splash
screen in a seperate thread which has it's own message pump. When the call
to Application.ExitThread() closes down the splash screen's thread, form and
message pump, the main form (and it's associated message pump) decides that
it has to process a WM_CLOSE message but i can't figure out who, what where
is firing that message. The result of this is that the main form has its
visible property set to false when the splash screen closes. I thought that
the use of the Application.Run() overload that doesn't take a Form as a
parameter wouldn't attach an event handler to the Form.Closed event like it
does in the other overload which is what i thought would be the thing w

Please note: I've seen lots of ways to implement splash screens on the news
groups etc and the examples i've seen are all pretty wanky if you ask me,
I'm not interested in how you have implemented your splash screen, i'm only
interested in explaining the behaviour that i'm seeing as it not only
relates to a splash screen but to other forms we display in our application.
the code below is the simplest i could come up with that demonstrates the

burger flavoured snack

using System;
using System.Threading;
using System.Windows.Forms;
namespace SplashTest
class SplashScreenViewer
Form splashForm;

public void Show()
Thread splashThread = new Thread(delegate()
splashForm = new Form();
splashForm.Text = "Splash Form";
splashForm.TopMost = true;

Thread sleepThread = new Thread(delegate()
if (splashForm.InvokeRequired)
splashForm.BeginInvoke(new MethodInvoker(delegate() {
Application.ExitThread(); }));


static class Program
static void Main()

SplashScreenViewer viewer = new SplashScreenViewer();

Form mainForm = new Form();
mainForm.Text = "Main Form";

Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.