473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

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);
}
}
}
Nov 17 '05 #1
0 2413

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: cube | last post by:
In thread i've got something like this Application.Run(new Form()); But programm shows Form and waits for events. Is there any solution to back from Form()? whithout Application.Exit or...
3
by: Matthias Jentsch | last post by:
Hello, I have a simple testapplication: public class Test : ApplicationContext { private static void Main () { Application.Run(new Test()); }
1
by: Brendan Miller | last post by:
I am trying to close my application using Application.exit() in the frmMain_Closing event. When the form closes the process does not. My application only has one form (no other classes either). ...
4
by: Chuck | last post by:
Hello everybody, I need to abort execution during start up, while the constructor called by Application.Run is executing. If the database fails to connect during my application's startup I...
23
by: jm | last post by:
This works, but I don't know why. static void Main() { // Queue the task. ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc),new Form1()); Application.Run(); }
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
4
by: Bob Day | last post by:
Using VS 2003, VB.net... I am confused about the Application.Exit method, where the help states "This method does not force the application to exit." Aside from the naming confusion, how do I...
0
by: Ralf Gedrat | last post by:
Hello! I have a Application, this throws after some time following exception: Item has already been added. Key in dictionary: "- 1" key being added: "- 1" I use Application.Run with...
12
by: Pete Smith | last post by:
Which is the appropriate one to use in the above choice? VB.Net. .Net Framework 1.1 Thank you, Pete
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.