CHAPTER 14 BUILDING MULTITHREADED 462 TITHREADED APPLICATIONS (Web host forum)

CHAPTER 14 BUILDING MULTITHREADED 462 TITHREADED APPLICATIONS Figure 14-6. Debugging a thread with Visual Studio 2005 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: public enum ThreadPriority { AboveNormal, BelowNormal, Highest, Idle, Lowest, Normal, // Default value. TimeCritical } If you were to assign a thread s priority level to a value other than the default (ThreadPriority. Normal), understand that you would have little control over when the thread scheduler switches between threads. In reality, a thread s priority level offers a hint to the CLR regarding the importance of the thread s activity. Thus, a thread with the value ThreadPriority.Highest is not necessarily guaranteed to given the highest precedence. Again, if the thread scheduler is preoccupied with a given task (e.g., synchronizing an object, switching threads, or moving threads), the priority level will most likely be altered accordingly. However, all things being equal, the CLR will read these values and instruct the thread scheduler how to best allocate time slices. All things still being equal, threads with an identical thread priority should each receive the same amount of time to perform their work. In most cases, you will seldom (if ever) need to directly alter a thread s priority level. In theory, it is possible to jack up the priority level on a set of threads, thereby preventing lower-priority threads from executing at their required levels (so use caution). Source Code The ThreadStats project is included under the Chapter 14 subdirectory. Programmatically Creating Secondary Threads When you wish to programmatically create additional threads to carry on some unit of work, you will follow a very predictable process: 1. Create a type method to be the entry point for the new thread. 2. Create a new ParameterizedThreadStart (or legacy ThreadStart) delegate, passing the address of the method defined in step 1 to the constructor.
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Leave a Reply