0

My second form won't open, willing to give more details if needed

After clicking on the button, it will proceed to the next form but it just closes before it there

    private void btnNext_Click(object sender, EventArgs e)
    {

        frmGame_3_ v = new frmGame_3_();
        this.Close();
        v.Show();
   }

This is what shows when the program closes on me.

The thread 0x21fc has exited with code 259 (0x103). The thread 0x22b8 has exited with code 259 (0x103). 'ICSCulminating.vshost.exe' (CLR v4.0.30319: ICSCulminating.vshost.exe): Loaded 'C:\Users\Owner\Desktop\ICSCulminating(David)e3\ICSCulminating\bin\Debug\ICSCulminating.exe'. Symbols loaded. The thread 0x207c has exited with code 259 (0x103). The thread 0x23c4 has exited with code 259 (0x103). The program '[7568] ICSCulminating.vshost.exe' has exited with code 0 (0x0).

Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67
  • 5
    Try `this.Hide()` instead of `this.Close()`. Typically, closing the main form ends the application. – adv12 Jan 17 '15 at 02:38

1 Answers1

0

You can, as suggested by commenter adv12, hide the form instead of closing it. This avoids the problem of the closing of the main form causing your event loop to terminate and the program to exit.

However, it means you are leaving the unused form around, undisposed. IMHO, even if this is not a serious problem per se, it would be better to fix the issue in a cleaner way.

That is, change your program's Main() method so that it uses the parameter-less overload of the Application.Run() method. This removes the dependency on the initial form so that you can close it without the whole program exiting. Then, when you to want to close the program, you can call the Application.ExitThread() method (or Application.Exit() if you prefer).

In your Main() method (found in the Program.cs file of your project), change the last line of the method, which will look something like this:

Application.Run(new Form1());

…to this:

new Form1().Show();
Application.Run();

Note: the name of your main Form subclass may be something other than Form1. Obviously, use whatever class name is in your own code now, if it's not Form1.

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136