C # child thread still works even with main thread output

I happened to read a sample Semaphore class, as shown below: msdn: https://msdn.microsoft.com/en-us/library/system.threading.semaphore%28v=vs.110%29.aspx

This is a console application, however, something confused me that child threads can even work with the outputs of the main thread. threads

From my understanding, when the main thread / process terminates, all child threads will be stopped, so we usually signal and expect the child threads to end before the main thread stops. Am I mistaken, or was the behavior changed in .net due to the link?

+1
source share
1 answer

If you want the child thread to be interrupted when the parent thread terminates, it must be set as the background thread.

t.IsBackground = true; t.Start(i); 

Otherwise, all foreground threads terminate before the process is complete.

+4
source

All Articles