How to kill application?

My windows form starts like this:

[STAThread]
static void Main()
{
     My_App ma =
new My_App();
     Application.Run(ma);
}

When I get into the "ma" class, I check to see if the user is online. If he is not, I just need to kill the whole app. However, I'm having trouble killing the main form from my "ma" class, so the user just sees a blank form on the screen. Any ideas

thanks for any help.



Answer this question

How to kill application?

  • Martin Fierz

    is there any more code you could post up than what you have originally

  • Gary Cawley

    hmm, not sure we are thinking the same thing...

    I have no problem killing the ma class, it's the main form that calls the ma class I'm having trouble killing.

    The ma class checks if the user is online. If he is not online, the ma class does a this.close() and then a blank form opens up, which is the main form that originally called the ma class. I've also tried Application.Exit with the same results.


  • Sudhir

    Is My_App a form When you call Application.Run with a form object as the parameter, that form becomes the main form for the application; when you close that form, the application exits automatically. This is the preferred method of running Windows Forms applications. If My_App is an application context, you should do your check before the form is ever shown, and if the check fails then call ExitThread immediately.

  • Pooneh

    To kill an application:

     

    Application.Exit();

    you could also do this.Close(); which would close a form

    you could also raise an event in ma to alert/notify the caller to close the ma instance which would probably be a better and best practice I believe :)



  • cvwilletts

    Should work when you call ma.Close()

    are you calling Application.Run(someOtherForm) any where else on the app



  • How to kill application?