Background Threads in C#

.net, c#, multithreading

Solution

1) What is the advantage of keeping a thread as background thread?

The Advantage is that a Background Thread doesn't stop the Program from terminating. In a large Application it could be a bit hard to deactivate all threads if you want to quit the Application.

Apart from Join() could i use other techniques to keep the main thread wait?

If yo want to make the Main program wait why do you make the thread a background thread in the first place then??? Besides of Join() you could use a EventWaitHandle or Monitor to make the main method wait.

Problem

I am new to C#.I learnt that normally all threads are foreground until unless you explicitly specify it as "background" thread using IsBackGround= true . Some doubts popped in to my mind. 1) What is the advantage of keeping a thread as background thread? 2) When executing the folowing code : ``` static void Main(string[] args) { Thread worker = new Thread(SayHello); worker.IsBackground = true; worker.Start(); Console.WriteLine("Hello From Main"); } static void SayHello() { Console.WriteLine("Hello World"); Console.ReadKey(true); } ``` i need to use worker.Join() to keep the main thread to wait as the program terminates immediately. Apart from Join() could i use other techniques to keep the main thread wait ?

Original source