0

I am new to C# programming, and I recently got this form application project from my coworker. Inside FormClosed event method, I see two lines of code:

Environment.Exit(0);
Application.Exit();

Then I looked them up to see the difference, and I read many SO posts about this. Many say if you are using

Application.Run();

method to start the form application, use

Application.Exit();

However, many also say just using

Environment.Exit(0);

is enough too. So after all, which needs to be used? The more I read, the more I get confused and at a loss which to use. I also noticed that if I put breakpoints on both lines, when the program comes to the line:

Environment.Exit(0);

the form closes and goes back to the coding screen. So I switched the order so both of them will be executed, but is it even correct to run both of them upon closing the application?

jun
  • 55
  • 1
  • 10
  • When you pass an int to `Environment.Exit` is the return code of the application, if you don't pass any it's like passing `0`, which is the application ended well. – dcg Jun 28 '17 at 12:27
  • 2
    After all you don't actually need any of them in your `FormClosing` event – Rahul Jun 28 '17 at 12:28

0 Answers0