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!!!
Taoge wrote:
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