The thread must also be executing a piece of code. So to produce a thread, you must first write a method for the thread, which is the code that the thread runs to execute. (Find someone to do something) the method is called by a delegate when the thread starts.
(Benefits of delegation)
(When a thread starts, a delegate is invoked, and the delegate executes the appropriate method to implement the thread execution method.)
L 4 steps to generate a thread: • Write the method that produces the thread • Reference the System.Threading namespace • Instantiate the thread class and pass in a delegate that points to the method that the thread is running. (This thread has been generated, but not yet) • Call the Start method of the thread instance, marking that the thread can be executed by the CPU, but the execution time is determined by the CPU. L Foreground thread: only all foreground threads are closed to complete the program shutdown. L Background thread: As long as all foreground threads end, the background thread ends automatically. Lstart () Start thread labort () terminates thread lthread.sleep (1) static method, which allows the current thread to stop running for a period of time lname thread name Lthread.currentthread get current thread reference
How to implement multithreading in. Net