(. Net 2.0) input parameters when creating a new thread

Source: Internet
Author: User
In earlier versions 1.1, it would be a bit difficult to input parameters to the new thread. In 2.0, because of the addition of the "ParameterizedThreadStart delegate, it simplifies the input of parameters.

Static void Main (string [] args)
{
Program instance = new Program ();
Thread threadSend = new Thread (new ParameterizedThreadStart (threadProc); // use ParameterizedThreadStart to delegate
String strParam = "this is the parameter I want to input ";
ThreadSend. Start (strParam); // input parameters here
}

Public static void threadProc (object param)
{
Console. WriteLine (param. ToString ());
// Do something
}

Pubulic static void threadProc (object param) // The parameter in the function declaration must be an object; otherwise, an error is returned.

If you want to input multiple parameters at a time, you can use object [] for encapsulation.

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.