Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# equivalent to Java's Thread.setDaemon?

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

like image 595
Epaga Avatar asked Feb 17 '11 14:02

Epaga


2 Answers

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;  
like image 83
Saurabh Gokhale Avatar answered Oct 16 '22 09:10

Saurabh Gokhale


Like this:

myThread.IsBackground = true; 
like image 11
Epaga Avatar answered Oct 16 '22 11:10

Epaga