It is also very important that threads are used extensively in ASP. Similarly, the implementation of creating a thread in ASP. NET is also very simple, just declare it and provide it with the method delegate at the starting point of the thread. When you create a new thread, you need to use the thread class, which has a constructor that accepts a ThreadStart delegate or Parameterizedthreadstart delegate. The delegate wraps the method that is called by the new thread when the Start method is called. After an object of the thread class is created, the thread 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 called.
Asp. NET's start () method is used to make the thread be scheduled to execute, it has two overloaded forms, which are described separately below.
(1) Make the operating system change the state of the current instance to threadstate.running, with the following syntax.
public void Start ()
(2) Enable the operating system to change the state of the current instance to threadstate.running and provide objects (parameters, various operating system resources) for the data to be used when the thread executes. The syntax is as follows.
public void Start (Object parameter)
Note: If the thread has been terminated, it cannot be restarted by calling the Start method again.
For example: Create a console application, customize a static method CreateThread (), instantiate the thread class object in the main () method, create a new thread, and call the start () method to start the thread. The specific code is as follows:
The static void Main (string[] args) { thread mythread;//declares the thread//creates an instance of the thread with the ThreadStart delegate of the thread start point myThread = new Threads ( Newthreadstart (CreateThread)); Mythread.start ();//start thread}public static void CreateThread () { console.write ("Create Thread");}
Note: The entry for the thread (in this case, CreateThread) takes no parameters.
ASP. NET thread Creation instance