I would like to sequentially show two separate forms. Here is the Main() function.
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new AccountForm());
Application.Run(new MainForm());
}
When I run this, the AccountForm is displayed normally, and then the MainForm is created and the Form_Load event is called, but the MainForm is never displayed and the program exits immediately.
If the Run(AccountForm) line is commented, the MainForm DOES display properly.
Apparently, when the AccountForm is closed using Application.Exit(), this is remembered by the Application object and it does not start another message loop on the next call to Run.
Any ideas how to make this work?
Added information, solved!
jmcilhinney made a simple suggestion to close the form instead of calling Application.Exit(). This worked perfectly. The code is simple and clean. Thank you!
For instance, is there some way to reset the state of the "Application" object?
Written in C# under Windows.
In actual use, there will be criteria on whether to run each piece. Sometimes, only the first will be run, sometimes only the second, and sometimes both. So this syntax is much simpler than other options I have considered.
In response to this being a duplicate: The other user wants his forms to be displayed simultaneously and independently. His situation can be handled with the suggestions give in that post. Those solutions do not work for the forms being displayed sequentially. (Or at least would not work cleanly and easily.) I really want to avoid building some complex logic that knows about both forms and the state of each and displays and destroys them as needed. My proposed sequential operation is dirt simple and very, very clean. It just looks like the developers of C# may have never considered anyone would do this.