Net-informations.com
SiteMap  | About    

this.close() Vs Application.Exit()

this.Close()

this.Close() will call Form.Close method of current form. When a form is closed, all resources created within the object are closed and the form is disposed. Whenever you close your program's startup form, the entire application should exit automatically, including closing all other open forms in the same project otherwise it just close the current form.

form-close
private void exitToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); }

Application.Exit()

System.Windows.Forms.Application.Exit() informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed, so it giving your forms the possibility to execute their cleanup code.

In a multithreading program, Application.Exit() will not terminate all your threads instead you are only exiting from the current thread context, while leaving any started foreground threads running. In this case you should take measures to kill your other threads, either in the main function or when in the OnClose event of your main form.

Environment.Exit()

Environment.Exit(0) terminates this process and gives the underlying operating system the specified exit code. It is more generally used in console applications.

public class MyProg { public static void Main(string[] args) { DoSomething(); Environment.Exit(0); } }






net-informations.com (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.