The implementation of creating a thread using ASP.net is actually very simple and can be achieved simply by declaring it and providing it with a method delegate at the starting point of the thread. 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. The delegate wraps the method called by the new thread when the Start method is invoked. After the object of the thread class is created, the threading object already exists and is configured, but the actual thread is not created, and the actual thread is created only after the Start method is invoked.
Asp. NET's Start method is used to make a thread scheduled for execution, and it has two overloaded forms, which are described separately below.
(1) causes the operating system to change the status of the current instance to threadstate.running, as follows.
(2) The operating system changes the state of the current instance to threadstate.running and selects the object that contains the data to be used by the method that the thread executes. The syntax is as follows.
public void Start (Object parameter)
Parameter: An object that contains the data to be used by the method that the thread executes.
Note: If the thread has terminated, it cannot be restarted by calling the Start method again.
For example, create a console application that customizes a static void type method CreateThread, then creates a new thread in the main method by instantiating the thread class object, and then calls the Start method to start the thread. The specific code is as follows:
static void Main (string[] args)
{thread
mythread;//declaring threads
//Creating an instance of the thread with the ThreadStart delegate of the thread's starting point
Mythread = New Thread (new ThreadStart (CreateThread));
Mythread.start ()//boot thread
} public
static void CreateThread ()
{
console.write ("Create thread");
}
Note: The entry of the thread (CreateThread in this case) takes no arguments.