C # process and thread

Source: Internet
Author: User

C # process and thread
I. Process and thread processes are the dynamic execution of a static command sequence and the basic unit for system resource allocation and scheduling. Information related to the process includes the user mark of the process, the compiled program that is being executed, the location of the program and data in the memory, and so on. A process can be divided into several independent execution streams, called threads. A thread is the basic unit of CPU scheduling. For example, in Windows, a user can run multiple applications at the same time, and each acknowledgment application is a process. Division of processes and threads is very important for improving software concurrency and implementing time-sharing processing. 2. Process is used to complete related processing tasks of related processes. You can start and stop processes on a computer, or query Process information. The general method for starting a Process is: (1) first create an instance of the Process class; (2) set the StartInfo attribute of the object; (3) Call the Start method of the object to Start the Process; 3. The Thread class is used to create and control threads. Operations on threads include starting threads, terminating threads, and merging threads to sleep the threads. 1. the startup Thread first creates a Thread t = new Thread (enterpoint); // enterpoint is the Thread entry, that is, the method of Thread execution. 2. There are two methods to terminate a thread. Method 1: Set a Boolean variable in advance. In other threads, you can modify the value of the variable and pass it to the thread, as a condition for determining whether it needs to terminate, the variable is cyclically checked in the thread to determine whether to exit the thread. This method is generally used in actual programming. Method 2: Call the Abort method of the Thread class to forcibly terminate the Thread. 3. The merge thread Join method is used to merge two parallel threads into one thread. If one thread t1 needs to wait for the execution of another thread t2 to continue, you can call the Join method of T2. 4. Call the Sleep method of the Thread class to Sleep the Thread. Such as Thread. Sleep (1000); 5. When threads compete for the CPU time slice, the CPU serves according to the Thread priority. For example, if the priority of thread t is set to the Highest, t. priority = ThreadPriority. Highest; 6. Thread Pool 7. synchronous synchronization means that there is a sequential association between multiple threads. You can use the lock statement to merge multiple threads into the logic.

Related Article

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.