C # Threads

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.