PC Review


Reply
Thread Tools Rate Thread

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

 
 
Guest
Posts: n/a
 
      28th Sep 2005
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
problem

cheers,
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;
splashForm.Show();
Application.Run();
});

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

splashThread.Start();
sleepThread.Start();
}
}

static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();

SplashScreenViewer viewer = new SplashScreenViewer();
viewer.Show();

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

Application.Run(mainForm);
}
}
}


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application.Run() Application.Exit and the 'Message Pump' orekin Microsoft C# .NET 6 3rd May 2005 09:24 AM
What's the main difference between Application.Exit() and Application.ExitThread()? Stan Microsoft Dot NET Framework Forms 1 30th Apr 2005 02:25 AM
application.exit, application.exitthread exit application problem =?Utf-8?B?TWlrZSBTaWx2ZXI=?= Microsoft Dot NET Framework Forms 2 24th Nov 2004 03:14 AM
Application.exit() vs Environment.exit(-1) vs Application.exitthread() Brendan Miller Microsoft C# .NET 1 5th Feb 2004 08:13 AM
How to run message pump in .NET? Jianxin Microsoft C# .NET 1 14th Jul 2003 04:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:30 PM.