PC Review


Reply
Thread Tools Rate Thread

Application.Exit() vs Environmrnt.Exit(0)

 
 
=?Utf-8?B?VGFvZ2U=?=
Guest
Posts: n/a
 
      19th Apr 2007
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!!!

 
Reply With Quote
 
 
 
 
Barry Kelly
Guest
Posts: n/a
 
      19th Apr 2007
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/
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application.Exit() Don't exit right away! iDesmet Microsoft VB .NET 4 2nd Jan 2009 09:56 PM
Code to Exit Web App and Exit Internet Explorer =?Utf-8?B?U2FuZHk=?= Microsoft ASP .NET 6 4th Aug 2005 09:28 PM
Outlook.exe posts an error on exit that it needs to exit. How do. =?Utf-8?B?SmFjayBIYWVzbHk=?= Microsoft Outlook Installation 0 4th Mar 2005 04:17 AM
application.exit, application.exitthread exit application problem =?Utf-8?B?TWlrZSBTaWx2ZXI=?= Microsoft Dot NET Framework Forms 2 24th Nov 2004 03:14 AM
Application.exit() vs Environment.exit(-1) vs Application.exitthread() Brendan Miller Microsoft C# .NET 1 5th Feb 2004 08:13 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:30 PM.