I have a published application in C#. Whenever I close the main form by clicking on the red exit button, the form closes but not the whole application. I found this out when I tried shutting down the computer and was subsequently bombarded by lots of child windows with I tried Also, whenever my forms call the
jordanz 1611 silver badge8 bronze badges asked Oct 19, 2012 at 15:50
6 From MSDN: Application.Exit
Environment.Exit
This article, Application.Exit vs. Environment.Exit, points towards a good tip: You can determine if
Reference: Why would Application.Exit fail to work?
answered Oct 19, 2012 at 15:56
Furqan SafdarFurqan Safdar 15.9k12 gold badges58 silver badges90 bronze badges 5
I know this is not the problem you had, however another reason this could happen is you have a non background thread open in your application.
When answered Oct 8, 2013 at 21:18
Scott ChamberlainScott Chamberlain 123k32 gold badges273 silver badges419 bronze badges
In short, yes. The entire application will end when the main form (the form started via If your entire application should always fully terminate whenever your main form is closed then you should just remove that form closed handler. By not canceling that event and just letting them form close when the user closes it you will get your desired behavior. As for all of the other forms, if you don't intend to show that same instance of the form again you just just let them close, rather than preventing closure and hiding them. If you are showing them again, then hiding them may be fine. If you want to be able to have the user click the "x" for your main form, but have another form stay open and, in effect, become the "new" main form, then it's a bit more complicated. In such a case you will need to just hide your main form rather than closing it, but you'll need to add in some sort of mechanism that will actually close the main form when you really do want your app to end. If this is the situation that you're in then you'll need to add more details to your question describing what types of applications should and should not actually end the program. answered Oct 19, 2012 at 16:51
In this case, the most proper way to exit the application in to override onExit() method in App.xaml.cs:
answered May 7, 2018 at 15:13
1 |