M
Mark Cranness
I have a Windows Forms application that does not exit when
Application.Exit() is called.
The problem is related to the Main() code used (below)
[STAThread]
static void Main() {
// Attempt login
DialogResult loginResult;
using (LoginForm loginForm = new LoginForm()) {
Application.Run(loginForm);
loginResult = loginForm.DialogResult;
}
// If login OK, then open main form
if (loginResult == DialogResult.OK) {
Application.Run(new MainForm());
}
}
Calling Application.Exit() (from a pushbutton or menu or
ThreadException handler) does not cause MainForm to close, or the app
to exit (the window remains open and active).
Calling Application.Run() twice (once for LoginForm and once for
MainForm) seems to be the root of the problem; If I don't first Run
the LoginForm, then Application.Exit() works as expected.
A simple workaround is to call Application.ExitThread instead, but I
am wondering why Application.Exit() does not work?
Thanks,
Mark
Application.Exit() is called.
The problem is related to the Main() code used (below)
[STAThread]
static void Main() {
// Attempt login
DialogResult loginResult;
using (LoginForm loginForm = new LoginForm()) {
Application.Run(loginForm);
loginResult = loginForm.DialogResult;
}
// If login OK, then open main form
if (loginResult == DialogResult.OK) {
Application.Run(new MainForm());
}
}
Calling Application.Exit() (from a pushbutton or menu or
ThreadException handler) does not cause MainForm to close, or the app
to exit (the window remains open and active).
Calling Application.Run() twice (once for LoginForm and once for
MainForm) seems to be the root of the problem; If I don't first Run
the LoginForm, then Application.Exit() works as expected.
A simple workaround is to call Application.ExitThread instead, but I
am wondering why Application.Exit() does not work?
Thanks,
Mark