473,804 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application.Exi t

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.Exi t() does the program keep
executing lines below it before finally closing the app down? If I put a
'return' under Application.Exi t() 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.For mBorderStyle=Fo rmBorderStyle.F ixedToolWindow;
frmLoginObj.Par ent = null;
frmLoginObj.Sho wInTaskbar = false;
frmLoginObj.Top Level = true;
frmLoginObj.Vis ible = false;

/* Show the dialog storing the result. */
DialogResult result = frmLoginObj.Sho wDialog();
if (result == DialogResult.Ca ncel)
{
//this.Close();
Application.Exi t();
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 2798
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.co m

"John F" <jf@rt.com> wrote in message
news:F9******** *************** ***********@mic rosoft.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.Exi t() does the program
keep
executing lines below it before finally closing the app down? If I put a
'return' under Application.Exi t() 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.For mBorderStyle=Fo rmBorderStyle.F ixedToolWindow;
frmLoginObj.Par ent = null;
frmLoginObj.Sho wInTaskbar = false;
frmLoginObj.Top Level = true;
frmLoginObj.Vis ible = false;

/* Show the dialog storing the result. */
DialogResult result = frmLoginObj.Sho wDialog();
if (result == DialogResult.Ca ncel)
{
//this.Close();
Application.Exi t();
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.co m

"John F" <jf@rt.com> wrote in message
news:F9******** *************** ***********@mic rosoft.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.Exi t() does the program
keep
executing lines below it before finally closing the app down? If I put a
'return' under Application.Exi t() 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.For mBorderStyle=Fo rmBorderStyle.F ixedToolWindow;
frmLoginObj.Par ent = null;
frmLoginObj.Sho wInTaskbar = false;
frmLoginObj.Top Level = true;
frmLoginObj.Vis ible = false;

/* Show the dialog storing the result. */
DialogResult result = frmLoginObj.Sho wDialog();
if (result == DialogResult.Ca ncel)
{
//this.Close();
Application.Exi t();
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
8528
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 condition and if it finds it it notifies the user with a MessageBox and then on the next line of code (example in a minute) it calls Application.Exit(). To my astonishment, I stepped through the code with the debugger, and watched it call...
1
17714
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). The form has a really long loop which generates approx. 700 .csv files. I do not create any threads myself (Application.exitthread() doesn't work either). To counteract this I have decided to use the Environment.exit(-1) method instead. What...
6
20088
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 quite a few words in this post but the questions are actually quite similar and should be fairly quick to answer ... (1) What is Happening with the Threads
1
3809
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 Application::Exit()? Does Application::Exit() terminate only the main thread and background threads, and not the foreground threads?
4
10863
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 force the application to exit? See **** below for my comments/questions in a simple example. ****In Sub Main, the Application.Exit works as expected, other sub main code is ignored, and when the end sub is reached the application shuts down....
3
2038
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 I change the End statement to Application.Exit(), the codes after the statement still been executed. So,
22
2259
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) Handles btnclose.Click Me.Close() System.Windows.Forms.Application.Exit End Sub
2
1365
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 String MyPath = FilePath ' Set the path. MyName = Dir(MyPath, FileAttribute.Directory) ' Retrieve the first entry. For i As Integer = 0 To 9999
4
9514
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
5121
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 fine. But how to do in such following scenario: if I need to give 2 option for user,1. Quit 2. Restart. In Quit option, I use Environment.Exit(0) to confirm the process will be stopped. In Restart option, I can't use Environment.Exit(0) , because...
0
9571
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10561
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5505
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
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 we have to send another system
2
3803
muto222
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.