473,625 Members | 2,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application.exi t() vs Environment.exi t(-1) vs Application.exi tthread()

I am trying to close my application using Application.exi t() 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.ex itthread() doesn't work either).
To counteract this I have decided to use the Environment.exi t(-1)
method instead.

What is the difference between the three methods?

Using environment.exi t() seems a strange way to do things considering there
is a Application.exi t method which claims to do what the Environment.exi t()
method does.
Nov 15 '05 #1
1 17685
Brendan Miller <ho**********@h otmail.com> wrote:
I am trying to close my application using Application.exi t() 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.ex itthread() doesn't work either).
Well that's the first problem - you *should* me creating a separate
thread to do your main processing. You should test a flag in that
thread every so often to see whether or not you should exit, and set
that flag in your closing event.
To counteract this I have decided to use the Environment.exi t(-1)
method instead.

What is the difference between the three methods?
Application.Exi t is to do with message pumps - it effectively means
that Application.Run (...) will return at that point.

Application.Exi tThread is similar to Application.Exi t, but only for the
message pump on the current thread.
Using environment.exi t() seems a strange way to do things considering there
is a Application.exi t method which claims to do what the Environment.exi t()
method does.


No it doesn't. How is:

<quote>
This method stops all running message loops on all threads and closes
all windows of the application. This method does not force the
application to exit.
</quote>

the same as

<quote>
Terminates this process and gives the underlying operating system the
specified exit code.
</quote>

? Where is the claim you were talking about?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2

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

Similar topics

3
5084
by: ZoombyWoof | last post by:
Hi. I'm pretty new to C# so this may seem like the dumbest question today, but I'm stuck. I have a small application, one Form that opens a connection to a database in its constructor. If the connection goes wrong I display a messagebox and I want the application to end after the user clicks OK. I cant make that happen..... If I use Application.Exit in my constructor the form still lives, if I do a this.dispose the program crashes and...
4
11153
by: Chuck | last post by:
Hello everybody, I need to abort execution during start up, while the constructor called by Application.Run is executing. If the database fails to connect during my application's startup I want to display a message (no problem here) and then abort the program. However, after the attached code executes I end up with my main form and a wait cursor! If I click on the X the form closes. Boss doesn't think an unhandled exception will...
6
20065
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
3790
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?
2
1872
by: Dan Keeley | last post by:
Hi, I have some code which needs to do close down the application and i'm trying to fire it in the catch of a try. However it doesnt work. The application does not exit! Any ideas? Thanks,
4
10852
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....
4
4109
by: vul | last post by:
I start the application with Application.Run(New MDIMain) in Sub Main. MDIMain is the mdi form which loads and then calls Login form. I'm using Application.Exit to terminate my VB 2005 application on Login screen if user clicks on Cancel button. When I do this I get a sound as MessageBox produces. I do not see any messages, but VB environment works abnormally after that. It doesn't switch modules until I minimize it and maximize again or...
4
9504
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
5100
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
8251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8182
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
8688
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...
1
8352
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,...
1
6115
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4085
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
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1800
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1496
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.