Application.Exit

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello All,

I have an app that I call a Login form in. I have 2 buttons on the login
form. 1 passes back OK and the other Cancel. When I click cancel, I simply
want to catch it in the main app and shut the application down.

My question is, why when you issue Application.Exit() does the program keep
executing lines below it before finally closing the app down? If I put a
'return' under Application.Exit() it exits quickly. If I don't and I trace
it through the debugger it will run through all the code beneath it.

private void Login()
{
frmUserLogin frmLoginObj = new frmUserLogin();
frmLoginObj.FormBorderStyle=FormBorderStyle.FixedToolWindow;
frmLoginObj.Parent = null;
frmLoginObj.ShowInTaskbar = false;
frmLoginObj.TopLevel = true;
frmLoginObj.Visible = false;

/* Show the dialog storing the result. */
DialogResult result = frmLoginObj.ShowDialog();
if (result == DialogResult.Cancel)
{
//this.Close();
Application.Exit();
return; // Return here does the trick, but I shouldn't need it.
}
Other code below here gets ran without the 'return'
 
John,

When you call Exit, a WM_QUIT message is sent to the message loop for
the UI thread telling it to quit. That being said, the code doesn't just
exit, it will progress beyond the call to Exit.

This is why you are seeing the behavior you see.

Hope this helps.
 
Thanks Nicholas. Makes sense...
--
John F


Nicholas Paldino said:
John,

When you call Exit, a WM_QUIT message is sent to the message loop for
the UI thread telling it to quit. That being said, the code doesn't just
exit, it will progress beyond the call to Exit.

This is why you are seeing the behavior you see.

Hope this helps.
 
Back
Top