ASP. NET thread Creation instance

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.