Welcome to MSDN Blogs Sign in | Join | Help

Syndication

Tags

    No tags have been created or used yet.
Why doesn't my process terminate even after main thread terminated
Sometimes you may wonder why your .NET application didn't terminated even after the main thread is terminated. Infact I was boggled with this problem for some time.
Finally I figured out that .NET does not terminates a process on the termination of main thread if there are other threads running. The new definition for determining process abortion is as follows:
"Once all foreground threads belonging to a process have terminated, the common language runtime ends the process by invoking 'Abort' on any background threads that are still alive"

This means that if you want your application to exhibit the same behavior (as I was expecting [:)]), make sure that you set all the threads background property to true (except for main thread). For complete details on this thread property, follow http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingthreadclassisbackgroundtopic.asp

Published Sunday, September 04, 2005 11:12 PM by neerajag

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Link Listing - September 4, 2005 @ Sunday, September 04, 2005 11:50 PM

.NET Reference Bot for MSN Messenger
[Via: Scott Van Vliet ]
ASP 2.0 Training [Via: trobbins ] ...

Christopher Steen

# re: Why doesn't my process terminate even after main thread terminated @ Thursday, October 30, 2008 5:36 AM

Use Environment.Exit to terminate thread or use any bool variable to keep refernce of each thread. And when you set this as false terminate that thread.

Mayank Sugandhi

Leave a Comment

(required) 
required 
(required) 
Page view tracker