Application.Exit

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'
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top