According to the Apress Support page, there is no Errata for the C# Threading Handbook.
This is too bad because that means that there is no central repository for errata, code listings and other stuff for this really great book.
Here is the first real bug I've found in this book.
On pages 44 and 45 you will find a listing for the ThreadPriority2.cs file. Here is the corrected code.
using
System;
using
System.Threading;
namespace
ThreadPriority2
{
class ThreadPriority
{
public static Thread worker;
public static Thread worker2;
static void Main(string[] args)
{
Console.WriteLine("Entering void Main()");
worker =
new Thread(new ThreadStart(FindPriority));
worker2 =
new Thread(new ThreadStart(FindPriority));
// Lets give a name to the thread
worker.Name =
"FindPriority() Thread";
worker2.Name =
"FindPriority() Thread 2";
// Give the new thread object the highest priority
worker2.Priority = System.Threading.
ThreadPriority.Highest;
worker.Start();
worker2.Start();
Console.WriteLine("Exiting void main()");
Console.ReadKey();
}
public static void FindPriority()
{
Console.WriteLine("Name: " + Thread.CurrentThread.Name);
Console.WriteLine("State: " + Thread.CurrentThread.ThreadState.ToString());
Console.WriteLine("Priority: " + Thread.CurrentThread.Priority.ToString());
}
}
}
The only difference is that in the book the FindPriority routine, the original code refers to the thread variable “worker.” as opposed to “Thread.CurrentThread.”