I’ve just read up on Thread.IsBackground and if I understand it correctly, when it’s set to false the Thread is a foreground thread which means it should stay alive until it has finished working even though the app have been exited out. Now I tested this with a winform app and it works as expected but when used with a console app the process doesn’t stay alive but exits right away. Does the Thread.IsBackground behave differently from a console app than a winform app?
I’ve just read up on Thread.IsBackground and if I understand it correctly, when it’s
Share
The
Thread.IsBackgroundproperty only marks if the thread should block the process from exiting. It doesn’t perform any magic to keep the thread alive until some sort of explicit exit.To quote the Thread.IsBackground Property MSDN (emphasis mine):
In order to keep your console app alive you’ll need to have some sort of loop which will spin until you ask it to stop via a flag or similar. Windows Forms applications have this built in because of their message pump (I believe).