Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application.Exit

Tags:

I am using VSTS 2008 + .Net 3.5 + C# to develop Windows Forms application. My confusion is, seems Application.Exit does not force application to terminate? If not, which method should I call to make application terminate?

EDIT 1:

Normally the main method is like this, how to exit Main function gracefully without calling Environment.Exit?

    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        try
        {
            Application.Run(new Form1());
        }
        catch (Exception ex)
        {
            Console.WriteLine (ex.Message);
        }
    }

thanks in advance, George

like image 602
George2 Avatar asked Jun 29 '09 08:06

George2


People also ask

What is application Exit?

The Exit method stops all running message loops on all threads and closes all windows of the application. This method does not necessarily force the application to exit. The Exit method is typically called from within a message loop, and forces Run to return.

What is the statement that closes the form?

this.Close() When a form is closed, all resources created within the object are closed and the form is disposed.

How do you exit an application in Visual Basic?

Just Close() all active/existing forms and the application should exit. ok.


1 Answers

Application.Exit really just asks the message loop very gently.

If you want your app to exit, the best way is to gracefully make it out of Main, and cleanly close any additional non-background threads.

If you want to be brutal... Environment.Exit or Environment.FailFast? note this is harsh - about the same as killing your own Process.

like image 112
Marc Gravell Avatar answered Sep 19 '22 13:09

Marc Gravell