'WinForms
Application.Exit();
'WPF
Application.Shutdown();
'Console
Environment.Exit(exitCode);
Can anyone list the advantages/disadvantages of above methods.
When to use, how to use etc..
Dont post any links or copy paste, this for knowledge sharing from persons who already experienced with above methods.
Loading


VulpesRank #55 · 29.2K reputationPosted Mar 9, 2011, 5:30 AM EST
Application.Shutdown() is (broadly) the equivalent of Application.Exit() in a WPF application. However, you have a bit more control as you can set the ShutDownMode so that the application shuts down when the main window closes, the last window closes or only when this method is called.
Environment.Exit() kills all running threads and the process itself stone dead. This should only be used in WF or WPF as a last resort when the more graceful methods are not working for some reason. It can also be used to make an abrupt exit from a console application.
Sam HobbsRank #107 · 20.5K reputationPosted Mar 9, 2011, 7:04 PM EST
VulpesRank #55 · 29.2K reputationPosted Mar 9, 2011, 11:45 PM EST
return 0;
Jim Snyder4 reputationPosted Sep 9, 2016, 10:40 AM EDT
Jim Snyder4 reputationPosted Sep 9, 2016, 10:56 AM EDT