Using Create a thread's implementation method is actually very simple. You can implement it by declaring it and providing it with a method delegate at the thread's start point. When creating a new thread, you need to use the Thread class, which has a constructor that accepts a ThreadStart delegate or a ParameterizedThreadStart delegate. This delegate wraps the method called by the new thread when the Start method is called. After creating the object of the Thread class, the thread object already exists and is configured, but the actual thread is not created. At this time, the actual thread will be created only after the Start method is called.
The Start method is used to make threads scheduled for execution. It has two overload forms, which are introduced separately below.
(1) Causes the operating system to change the status of the current instance to, the syntax is as follows.
public void Start ()
(2) Make the operating system change the status of the current instance to and select an object that provides the data to use for the method executed by the thread. The syntax is as follows.
public void Start (Object parameter)
parameter: an object that contains the data to be used by a method executed by a thread.
Note: If the thread has been terminated, it cannot be restarted by calling the Start method again.
For example: Create a console application where you customize a static void type method createThread, then create a new thread in the Main method by instantiating the Thread class object, and then start the thread by calling the Start method. The specific code is as follows:
static void Main(string[] args) { Thread myThread; //Declare thread// Create an instance of the thread using ThreadStart at the thread start pointmyThread = new Thread(new ThreadStart(createThread)); ();//Start the thread} public static void createThread() { ("Create thread"); }
Note: The thread's entry (createThread in this case) does not contain any parameters.