Thread is a single sequential control process in a process. A thread is an entity in a process. A process can have multiple threads, and a thread must have a parent process.
Threads generally have three basic states of read,blocking and operation. The basic operation of five kinds of threads is derived from three basic states. First, derive, threads are derived from within the process. Second, schedule, select a ready thread to enter the operation state. Third, block, if a thread waits for an event to occur during execution, it is blocked. IV, unblock, if the event starts, the thread is unblock and enters the ready queue. Five, finish, the thread ends, the register context it executes, and the stack contents are freed.
The new thread is the newly generated thread object, and it has not yet allocated resources. Therefore only the start () or close () method can be used.
The runable state is when the thread runs on the start () method, gets the required resources for the thread, and calls the run () method to execute.
Not runable non-running state is entered in the state where the following event occurs, the Suspend () method is called, The Sleep () method is called, the thread waits for the condition variable with wait (), and the thread is in I/O wait.
Dead is when the run () method returns, or another thread calls the Stop () method, and the thread enters the dead state.
Some functions of the Thread class
Start () startup
Sleep () pause set number of seconds
Abort () termination
Suspend () suspend thread, resume () available
Below is a simple example of thread.
Using System;usingSystem.Threading; Public classsimplethread{ Public voidMethod () {inti =1, j =2; intresult = i +J; Console.WriteLine ("thread{0} Value{1}", Appdomain.getcurrentthreadid (). ToString, result. ToString ()); } Static voidMain () {simplethread thread1=NewSimplethread (); Thread1. Method (); ThreadStart TS=NewThreadStart (thread1. Method); Thread T=NewThread (TS); T.start (); Console.ReadLine (); }}
C # Threads