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 MessageBox alerts I added.
I tried Application.Exit but it still calls all the child windows and alerts. I don’t know how to use Environment.Exit and which integer to put into it either.
Also, whenever my forms call the FormClosed or FormClosing event, I close the application with a this.Hide() function; does that affect how my application is behaving?
From MSDN:
Application.Exit
Environment.Exit
This article, Application.Exit vs. Environment.Exit, points towards a good tip:
You can determine if
System.Windows.Forms.Application.Runhas been called by checking theSystem.Windows.Forms.Application.MessageLoopproperty. If true, then Run has been called and you can assume that a WinForms application is executing as follows.Reference: Why would Application.Exit fail to work?