So I just had a very VERY difficult phone screen the other day.  It was a great experience though, because it's pointed me in the direction of a number of important topics that I'm weak on.  So this will be a series on those topics.  Hopefully round 2 will go a little smoother.  :-) 

At any rate, my first topic is threading.  I took an Operating Systems class in school, but it was

  1. In C
  2. Longer ago than I like to consider.

Definitely time to update my knowledge in this area

Foreground / Background Threads - What's the Difference?: 

The CLR doesn't close your program until all the foreground threads have ended.  On the other hand, background threads are viewed as only having relevance while foreground threads are running.  As a result, when the foreground threads end, your program ends.  The CLR will kill any background threads that were executing as necessary.  What's the code distinction?

[THREAD].IsBackground = true;

To illustrate, below is a heavily plagiarized code snippet from Pro C# with .Net 3.0 Primer, (page 467).

static void Main(string[] args)
{
   Thread bgroundThread = 
     new Thread(new ThreadStart(SomeFunction));
   bgroundThread.IsBackground = true;
   bgroundThread.Start();
}

Because bgroundThread is a background thread, this console application will end immediately, and whatever you have called in SomeFunction will not be executed.  By default, threads are created as foreground threads, so commenting out the IsBackground = true; line will mean the console application doesn't end until SomeFunction completes its work and returns.

What about the ThreadPool / BeginInvoke?

Threadpool threads are background threads, which is the opposite of the behavior you can expect from generating the Thread yourself.  Further, it's important to realize that when you create a delegate, and use BeginInvoke, you are not creating a thread, but queueing the work on the thread pool, which again means you're running on a background thread.