472,101 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,101 software developers and data experts.

Application.Exit() vs Environmrnt.Exit(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.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 following
application.restart() can't execute never. but if i use Application.Exit(),
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 4837
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.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 following
application.restart() can't execute never. but if i use Application.Exit(),
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.Exit 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.Exit 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.Exit is called, assuming not much other code follows the
call to Application.Run(). However, if there are other non-background
(Thread.IsBackground) threads in the process, or your application does
something else after calling Application.Run, then the process won't
exit immediately.

Environment.Exit(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.Exit. 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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Guinness Mann | last post: by
3 posts views Thread by John Wildes | last post: by
4 posts views Thread by Bob Day | last post: by
3 posts views Thread by Marcel Saucier | last post: by
7 posts views Thread by Jay | last post: by

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.