Why does my winforms app close after a few seconds of loading?

Calin Baenen - Mar 4 '21 - - Dev Community

All I do is start the window.

My code:

using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System;



partial class Program {
    List<Control> Elements;
    Dictionary<String, Color> ClrSchm = ColorScheme.LIGHTS_OUT;
    readonly Form Window;
    String Page = "";


    /**
    * Make a new program object.
    */
    private Program() {
        this.Elements = new List<Control>();



        this.Window = new Form();

        this.Window.ShowInTaskbar = true;
        this.Window.StartPosition = FormStartPosition.CenterScreen;
        this.Window.MinimumSize = new Size(500, 400);
        this.Window.Text = $"{Program.NAME} ({Program.VERSION})";

        this.Window.BackColor = this.ClrSchm["background"];
        this.Window.ForeColor = this.ClrSchm["foreground"];
        this.Window.Visible = true;



        this.Elements = Program.PAGES["."];
    }





    /**
    * Main method.
    */
    static void Main() {
        Program p = new Program();
        try {
            p.Run();
        } catch(Exception EXC) {
            Program.WriteLog(EXC);
        }
    }



    /**
    * Run method.
    */
    void Run() {
        //this.UpdateElements();
        Application.Run(this.Window);
    }
}
Enter fullscreen mode Exit fullscreen mode

PAGES:

/**
* Program class.
*/
partial class Program {
    private static readonly Dictionary<String, List<Control>> PAGES =
        new Dictionary<String, List<Control>>() {
            ["."] = {
                Program.ProduceButton(10, 10, text:"Settings"),
                Program.ProduceButton(10, 76, text:"New Program")
            }
        };
}
Enter fullscreen mode Exit fullscreen mode

The other part of this class isn't important, as I've commented out the call to the method UpdateElements. If it is important, let me know.

So, what am I doing wrong? Why does it just load, and then close? Because the program doesn't even leave behind an EXCEPTION_LOG.txt, like Program.WriteLog should be writing.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .