C # Winform: Is Application.Run () useful if I run a dialog form?
I always like to stick with the form class methods. Form.ShowDialog()
and Form.Close()
. Everything you need is included Form.DialogResult
. If you stick with just instantiating the forms and using the methods attached to them, this seems much cleaner in the long run. I don't feel like you will get anything out of using Application.Run () when launching the form dialog.
source to share
Yes, it ShowDialog
will create and run its own message loop. In fact, there are many different methods that you would not even think of to do this.
Application.Exit
instructs all running message loops to exit. I do not know enough about your statement to make a recommendation or use this method. But, in basic scenarios, I think you will find that its usefulness is limited at best.
Definitely when you don't want to use the default code that VS generates in a relation Application.Run
, but your statement you never use concerns me.
source to share
You can do this, but this is not a good design. Program.cs starts the application and contains skills, which means starting and stopping the application. The form it launches is a window that the user interacts with and should just contain this code.
For example, what if you later want to include this form in another application? Well, you have to change it because it calls Application.Exit (), which would be problematic. Also, if you have automated tests of a GUI module calling Application.Exit () is also not good.
source to share
You should just rely on the Form.Close () call to return control to the caller, not Application.Exit (). If the caller is Program.cs, then your application will terminate.
source to share