473,698 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application.Exi t() vs Environmrnt.Exi t(0)

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.Exi t(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.Exi t(0) to confirm the process will be stopped. In
Restart option, I can't use Environment.Exi t(0) , because following
application.res tart() can't execute never. but if i use Application.Exi t(),
the application can restart, but if the user choose quit next time. alas! the
process is going! it won't stop this time.
Hope my desception is clear :)
Pls Help!!!

Apr 19 '07 #1
1 5105
Taoge wrote:
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.Exi t(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.Exi t(0) to confirm the process will be stopped. In
Restart option, I can't use Environment.Exi t(0) , because following
application.res tart() can't execute never. but if i use Application.Exi t(),
the application can restart, but if the user choose quit next time. alas! the
process is going! it won't stop this time.
Hope my desception is clear :)
On the topic of your zombie process:

Application.Exi t causes the Windows UI message loop of the current
thread, if any, to exit. Understanding this requires understanding that
Windows UIs are based around a simple loop that iteratively retrieves a
message and dispatches it. The loop is contained in code called by
Application.Run (). So, Application.Exi t will cause Application.Run () to
return. If the only non-background thread in your application is the one
that is showing a UI and which has called Application.Run () at some
point in the past, then the process will usually exit some time after
Application.Exi t is called, assuming not much other code follows the
call to Application.Run (). However, if there are other non-background
(Thread.IsBackg round) threads in the process, or your application does
something else after calling Application.Run , then the process won't
exit immediately.

Environment.Exi t(retCode) causes the process to exit, and is more like
the Windows API ExitProcess.

I suggest you break into the application in the debugger when it is
still executing yet has called Application.Exi t. Check each thread and
see where they are. Some of them will be CLR threads for finalization,
GC, debugging, etc., but there should be some user threads in there that
are keeping the process alive.

-- Barry

--
http://barrkel.blogspot.com/
Apr 19 '07 #2

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

Similar topics

1
8516
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
17695
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
20078
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
3796
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?
3
1871
by: John Wildes | last post by:
Hello All I have an application that has one form. I start the application using a Application.Run(New frmMain) command in Sub Main(). When I exit, the exit menu Item simply does a Me.Close . It closes and ends the application, and closes the NotifyIcon I have specified for this application. When I use Application.Exit it closes the form and ends the application but the NotifyIcon doesn't remove itself unless you hover a mouse cursor...
4
10854
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....
20
2705
by: Peter Oliphant | last post by:
How does one launch multiple forms in an application? Using Photoshop as an example, this application seems to be composed of many 'disjoint' forms. Yet, they all seem somewhat 'active' in contrast to one of them always being 'modal' (e.g., if you are moving over a picture the 'Info' form will update the (x,y) screen location in realtime even if not the selected form. Also note that this example implies the various forms can communicate...
3
2052
by: Marcel Saucier | last post by:
I have written a Console Application then created a shortcut to it on my desktop. I was able to minimize the DOS window when I click my shortcut so I dont see anymore the DOS window But, using Task Manager to run the shortcut, I am not able to get rid of (minimize) the DOS window. Is there somebody that is aware of this problem ? My application is an agenda, so Task Manager runs it every 15 minutes, to
7
4311
by: Jay | last post by:
In my C# code, I'm attempting to display a message box then quit the win form application I'm writing if a certain type of error occurs when the application starts up. In the main form's constructor - FormMain() - if this error occurs, I display a message box then call Application.Exit(). The problem is that I also need to have some code in my FormMain_FormClosing event handler, but this prevents Application.Exit() from quitting the...
0
8671
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
8598
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
9016
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
8887
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
8856
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7709
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6515
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
5858
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
4613
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.