Using ApplicationContext rather than running a form. Application not quitting

C

Chukkalove

While trying to run an ApplicationContext rather than creating a new form, I
noticed that the application never quits.
I stripped the code out of it down to the bone and it still doesnt exit.
I put a break in the OnApplicationExit function, it's never reached
Any idea what i'm missing?



public class MyApplication : ApplicationContext
{

public MyApplication()
{
Application.ApplicationExit += new EventHandler(this.OnApplicationExit);

foobar();
foobar();

ExitThread();
}

private void OnApplicationExit(object o, System.EventArgs e)
{
DoSomething();
}


[STAThread]
static void Main()
{
Application.Run(new MyApplication());
}// function
 
T

Tasos Vogiatzoglou

A call to Application.Exit maybe.

Do you call it from somewhere ?

Regards,
Tasos
 
C

Chukkalove

I tried microsofts sample code in their ApplicationContext topic. They run
two forms which maintain a form counter on close.
When the form counter reaches zero ExitThread() is called, the
OnApplicationExit function is called and the application closes down.
I dont know if it might be something to do with having opened some forms,
but when i use my own forms I get this problem too.
I maybe don't understand what's going on in the background.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top