Michigan web site - CHAPTER 14 BUILDING MULTITHREADED APPLICATIONS 461 application

CHAPTER 14 BUILDING MULTITHREADED APPLICATIONS 461 application named ThreadStats. As you know, the static Thread.CurrentThread property retrieves a Thread type that represents the currently executing thread. Once you have obtained the current thread, you are able to print out various statistics: // Be sure to ‘use’ the System.Threading namespace. static void Main(string[] args) { Console.WriteLine(”***** Primary Thread stats *****n”); // Obtain and name the current thread. Thread primaryThread = Thread.CurrentThread; primaryThread.Name = “ThePrimaryThread”; // Show details of hosting AppDomain/Context. Console.WriteLine(”Name of current AppDomain: {0}”, Thread.GetDomain().FriendlyName); Console.WriteLine(”ID of current Context: {0}”, Thread.CurrentContext.ContextID); // Print out some stats about this thread. Console.WriteLine(”Thread Name: {0}”, primaryThread.Name); Console.WriteLine(”Has thread started?: {0}”, primaryThread.IsAlive); Console.WriteLine(”Priority Level: {0}”, primaryThread.Priority); Console.WriteLine(”Thread State: {0}”, primaryThread.ThreadState); Console.ReadLine(); } Figure 14-5 shows the output for the current application. 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 2005, you may access the Threads window during a debugging session (select Debug .Windows . Threads). As you can see from Figure 14-6, you can quickly identify the thread you wish to diagnose. Figure 14-5. Gathering thread statistics
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Leave a Reply