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 https://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingthreadclassisbackgroundtopic.asp
Comments
Anonymous
September 04, 2005
.NET Reference Bot for MSN Messenger
[Via: Scott Van Vliet ]
ASP 2.0 Training [Via: trobbins ] ...Anonymous
October 29, 2008
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.Anonymous
June 15, 2011
The comment has been removed