CHAPTER 19 MULTITHREADED, PARALLEL, AND ASYNC PROGRAMMING
}
Here is the current output:
***** Primary Thread stats *****
Name of current AppDomain: ThreadStats.exe
ID of current Context: 0
Thread Name: ThePrimaryThread
Has thread started?: True
Priority Level: Normal
Thread State: Running
The Name Property
While this code is more or less self-explanatory, do notice that the Thread class supports a property
called Name. If you do not set this value, Name will return an empty string. However, once you assign a
friendly string moniker to a given Thread object, you can greatly simplify your debugging endeavors. If
you are making use of Visual Studio, you may access the Threads window during a debugging session
(select Debug Windows Threads). As you can see from Figure 19-1, you can quickly identify the
thread you want to diagnose.
Figure 19-1. Debugging a thread with Visual Studio
The Priority Property
Next, notice that the Thread type defines a property named Priority. By default, all threads have a
priority level of Normal. However, you can change this at any point in the thread’s lifetime using the
ThreadPriority property and the related System.Threading.ThreadPriority enumeration, like so:
public enum ThreadPriority
{
Lowest,
713