Basically I have a Login window which should close once the user logs in and show another window, for now I’ve just hid it(Form.Hide()) however I do not wish to take unnescesary system resources and I don’t need the login window after I already logged in.
this is the code snippet where I perform the operation:
MainWindow w = new MainWindow();
TimeRegisterApI.Instance.Windows.Add(w.Text,w);
TimeRegisterApI.Instance.Windows[w.Text].Show();
this.Dispose();
Windows is a dictionary that stores references of forms with their title as the key.
TimeRegisterApi is a singleton.
Basically what happens is that my application exits after I login instead of just disposing the login window, when I want it to dispose(close and go to the garbage collector.)
I know that having the title as key might cause duplicate key entries but in my current design it’s no problem.
ok I fixed the problem, basically what happens is that when the window that is run from
program.csatapplication.run(window)gets disposed it closes the program because it’s the main window, I think it would be possible to do ane.cancelon the dispose event of this window, however I solved the problem by running the window in a newapplication.runlike this:from program.cs, relevant lines