This article is a mirror article of machine translation, please click here to jump to the original article.

View: 18422|Reply: 1

[Source] C# learns to use Thread threads

[Copy link]
Posted on 3/27/2017 5:32:28 PM | | |

. .NET framework is a runtime class library for C#, . .NET is a multi-threaded environment. A 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: read, blocking, and operation. From the three basic states, five basic operations of threads are derived. First, derive, threads are derived within a process. Secondly, schedule, select a ready thread to enter the operation state. Third, block, if a thread needs to wait for an event to occur during execution, it will be blocked. Fourth, unblock, if the event starts, the thread is unblocked, entering the ready queue. Fifth, finish, the thread ends, and the register context and stack contents it executed are released.

     A new thread is a newly generated thread object that has not yet allocated resources. Therefore, you can only use the start() or close() methods.

     The runable state is when the thread gets the resources necessary for the thread after the start() method runs and calls the run() method to execute.

     The Not Runable state is a state that enters when the following events occur, the suspend() method is called, the sleep() method is called, the thread uses wait() to wait for the condition variable, and the thread is waiting for I/O.

    Dead is when the Run() method returns, or another thread calls the stop() method, and the thread enters the dead state. Below are two simple examples of Thread.


Summary: Why use Thread (multi-threading), this is to prevent blocking the main thread, if you need to process a large amount of data, or call a time-consuming method, we need to use Thread multi-threading.

Example:


Not using multithreading: The interface is not responding... It's because multithreading isn't in use




Previous:Who is the real estate boss Wu Xuezhan behind the "mother insult case"?
Next:BundleTable does not load js and css files with min
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com