473,473 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Application.Exit

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.FixedT oolWindow;
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'

-------
Thanks,
John F
Feb 17 '06 #1
2 2769
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John F" <jf@rt.com> wrote in message
news:F9**********************************@microsof t.com...
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.FixedT oolWindow;
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'

-------
Thanks,
John F

Feb 17 '06 #2
Thanks Nicholas. Makes sense...
--
John F
"Nicholas Paldino [.NET/C# MVP]" wrote:
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John F" <jf@rt.com> wrote in message
news:F9**********************************@microsof t.com...
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.FixedT oolWindow;
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'

-------
Thanks,
John F


Feb 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Guinness Mann | last post by:
Pardon me if this is not the optimum newsgroup for this post, but it's the only .NET newsgroup I read and I'm certain someone here can help me. I have a C# program that checks for an error...
1
by: Brendan Miller | last post by:
I am trying to close my application using Application.exit() in the frmMain_Closing event. When the form closes the process does not. My application only has one form (no other classes either). ...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
1
by: Ioannis Vranos | last post by:
I am currently reading a chapter involving multithreading, and some sample code calls Environment::Exit() to terminate the application with all threads. What is the difference from...
4
by: Bob Day | last post by:
Using VS 2003, VB.net... I am confused about the Application.Exit method, where the help states "This method does not force the application to exit." Aside from the naming confusion, how do I...
3
by: oktave | last post by:
Hi, Anybody would like to tell me ther defference between Application.Exit() and End? I can use End to end my application no matter how many forms and codes after the End statement. But since...
22
by: Shelby | last post by:
Hi, I used System.Windows.Forms.Application.DoEvents() in a loop to handle user click close button . Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)...
2
by: Mike Johnson | last post by:
The sub is being called from the Sub New(). If I can't use Application.Exit() in this situation then how do I exit the application? please help. Public Sub Check_For_Dir() Dim MyPath, MyName As...
4
by: JIM.H. | last post by:
Here is the code I am having problem: static void Main(string args) { bool isPar = false; if ((args.Length == 1)) { if ((args(0).ToUpper() == "MYPAR")) { isPar = true;
1
by: =?Utf-8?B?VGFvZ2U=?= | last post by:
Hi All, When I use applcation.exit() in winForm application, the form closed, but the process is still going!! ( The debug process is still running if debug in VS IDE). Environment.Exit(0) works...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.