Threads in LinqPad
I am using LinqPad as a learning tool to enhance my C# skills, looking at the Programming in C# Exam Ref book it has the following code:
The book states that this should exit straight away as the thread is set to a IsBackground, however in LinqPad this writes out the ThreadProc 10 times. In Visual Studio this exits straight away as expected. Am I missing something in the way LinqPad handles threads.
Many Thanks
J.
public static class Program
{
public static void ThreadMethod()
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine("ThreadProc: {0}", i);
Thread.Sleep(1000);
}
}
public static void Main()
{
Thread t = new Thread(new ThreadStart(ThreadMethod));
t.IsBackground = true;
t.Start();
}
}
The book states that this should exit straight away as the thread is set to a IsBackground, however in LinqPad this writes out the ThreadProc 10 times. In Visual Studio this exits straight away as expected. Am I missing something in the way LinqPad handles threads.
Many Thanks
J.
Comments
Features that rely on this include hyperlinks that you can click to fetch more data (Util.OnDemand, Lazy, LINQ-to-SQL association properties, etc.), and the .Cache() extension method for sequences (or Util.Cache), which gives you the benefits of a REPL.