CHAPTER 14 BUILDING MULTITHREADED 460 TITHREADED APPLICATIONS (Cheap web hosting)
CHAPTER 14 BUILDING MULTITHREADED 460 TITHREADED APPLICATIONS The System.Threading.Thread Class The most primitive of all types in the System.Threading namespace is Thread. This class represents an object-oriented wrapper around a given path of execution within a particular AppDomain. This type also defines a number of methods (both static and shared) that allow you to create new threads within the current AppDomain, as well as to suspend, stop, and destroy a particular thread. Consider the list of core static members in Table 14-2. Table 14-2. Key Static Members of the Thread Type Static Member Meaning in Life CurrentContext This read-only property returns the context in which the thread is currently running. CurrentThread This read-only property returns a reference to the currently running thread. GetDomain() These methods return a reference to the current AppDomain or the ID GetDomainID() of this domain in which the current thread is running. Sleep() This method suspends the current thread for a specified time. The Thread class also supports several instance-level members, some of which are shown in Table 14-3. Table 14-3. Select Instance-Level Members of the Thread Type Instance-Level Member Meaning in Life IsAlive Returns a Boolean that indicates whether this thread has been started. IsBackground Gets or sets a value indicating whether or not this thread is a background thread (more details in just a moment). Name Allows you to establish a friendly text name of the thread. Priority Gets or sets the priority of a thread, which may be assigned a value from the ThreadPriority enumeration. ThreadState Gets the state of this thread, which may be assigned a value from the ThreadState enumeration. Abort() Instructs the CLR to terminate the thread as soon as possible. Interrupt() Interrupts (e.g., wakes ) the current thread from a suitable wait period. Join() Blocks the calling thread until the specified thread (the one on which Join() is called) exits. Resume() Resumes a thread that has been previously suspended. Start() Instructs the CLR to execute the thread ASAP. Suspend() Suspends the thread. If the thread is already suspended, a call to Suspend() has no effect. Obtaining Statistics About the Current Thread Recall that the entry point of an executable assembly (i.e., the Main() method) runs on the primary thread of execution. To illustrate the basic use of the Thread type, assume you have a new console
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.