. .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
|