Application.Exit vs. Environment.Exit

I looked over my sources and saw that i used Application.Exit and sometimes Environment.Exit... Without ever knowing, when exactly to use the right procedure!

This article gave me clearness
Application.Exit vs. Environment.Exit

Msdn Help
Application.Exit
Environment.Exit

Essence of the blog post!

if (System.Windows.Forms.Application.MessageLoop)
{
   // Use this since we are a WinForms app
   System.Windows.Forms.Application.Exit();
}
else
{
   // Use this since we are a console app
   System.Environment.Exit(1);
}
Good example - Code determines in which context used, Console, Winforms, Class Library, and calls right method

1 comment:

Post a Comment

Latest Posts

Popular Posts