C# equivalent to Java's Thread.setDaemon?

Epaga picture Epaga · Feb 17, 2011 · Viewed 9.5k times · Source

How do I set a thread to a daemon thread in C#?

Answer

sgokhales picture sgokhales · Feb 19, 2011

Though you have already answered your own question, I would still like to elaborate more on it.

In C# .NET, unlike in Java

   C# Background threads ~ Java Daemon threads  
   C# Foreground threads ~ Java User threads

By default, threads you create explicitly are foreground threads.

"Background threads are identical to foreground threads, except that background threads do not prevent a process from terminating." (reference)

You can make a thread Daemon by

thread.IsBackground = true;